igloocoder.com Wiki

Edit

This has been been removed from the commons framework. If you want fluent creation of Castle Windsor, it is now supported in the trunk build.





CSinsor is a wrapper around the Windsor container provided by the Castle project. Container functionality is exactly the same as Windsor. All that is provided is a new mechanism for initializing the container itself.

In all cases it is loading only objects that:
- aren't abstract
- aren't interfaces
- implement at least one interface


Edit

Sample

Edit

Simple Use

This will intialize a CSinsorContainer with all the objects from the IglooCoder.Commons.Tests.dll assembly.

IWindsorContainer container = new CSinsorContainer().InitializeWith(
new CSinsorAssemblyInitializer()
.For("IglooCoder.Commons.Tests.dll")
);

Edit

Multiple Assemblies

IWindsorContainer container = new CSinsorContainer().InitializeWith(
new CSinsorAssemblyInitializer()
.For("IglooCoder.Commons.Tests.dll")
.For("IglooCoder.Commons.CSinsor.dll")
.For("SomeCompany.SomeProduct.Data.dll")
);

Edit

Exclusion Filters

In this example we show how to exclude components when loading the container. Because of the CSinsorAssemblyInitializer's fluent interface it's possible to add as many filters as you need.
The WithExclusionOf method accepts a Predicate as it's parameter. When loading the container, all types are run through the provided Predicates and those which return false are loaded. As you can see in this example, there are three different namespaces being excluded from loading.

NOTE: Exclusions will be applied to all assemblies that are being loaded.

IWindsorContainer container = new CSinsorContainer().InitializeWith(
new CSinsorAssemblyInitializer()
.For("IglooCoder.Commons.Tests.dll")
.Add().ExclusionUsing(t => t.Namespace == "IglooCoder.Commons.Tests.HelperClassesForReflection.SecondNamespace")
.Add().ExclusionUsing(t => t.Namespace == "IglooCoder.Commons.Tests.HelperClassesForReflection.SomeNamespace")
.Add().ExclusionUsing(t => t.Namespace == "IglooCoder.Commons.Data")
);


In this example we are excluding any component that does not belong to the provided namespace.

IWindsorContainer container = new CSinsorContainer().InitializeWith(
new CSinsorAssemblyInitializer()
.For("IglooCoder.Commons.Tests.dll")
.Add().ExclusionUsing(t => t.Namespace != "IglooCoder.Commons.Tests.HelperClassesForReflection.SecondNamespace")
);


Additionally we could exclude a specific component.

IWindsorContainer container = new CSinsorContainer().InitializeWith(
new CSinsorAssemblyInitializer()
.For("IglooCoder.Commons.Tests.dll")
.Add().ExclusionUsing(t => t.Name == "SqlConnection")
);

Edit

Constructor Parameters

Windsor's Xml based configuration allows for the addition of constructor parameter values. Those values are then applied to the constructor when the object is instantiated. CSinsor provides the ability to create constructor parameter values using it's fluent interface.

IWindsorContainer container = new CSinsorContainer().InitializeWith(
new CSinsorAssemblyINitializer()
.For("IglooCoder.Commones.Tests.dll")
.Parameters(Parameter.For()ImplementedBy().Key("partName").Value("Some Part Name Goes Here"))
);

It's possible to add as many parameters as you need.

IWindsorContainer container = new CSinsorContainer().InitializeWith(
new CSinsorAssemblyInitializer()
.For("IglooCoder.Commones.Tests.dll")
.Parameters(
Parameter.For()ImplementedBy().Key("partName").Value("Some Part Name Goes Here"),
Parameter.For()ImplementedBy().Key("id").Value("1")
)
);

ScrewTurn Wiki version 2.0.27. Some of the icons created by FamFamFam.