One of the great new features with StructureMap 2.5 is the ability to have the container auto-wire you dependencies. This means that if you want to you do not need to register all your types.
Prior to this release if you wanted to map IFoo to Foo you needed to do something like this:
StructureMapConfiguration.ForRequestedType<IFoo>().TheDefaultIsConcreteType<Foo>();
Although this was not a major pain or even a major issue to me, I would love the ability to not have to create TONS of lines of wasted code simply to wire my interfaces to my concretes.
With 2.5 you can do the following and have the container do all the grunt work for you.
ObjectFactory.Initialize(
x =>
{
x.Scan( scanner =>
{
scanner.TheCallingAssembly();
scanner.WithDefaultConventions();
} );
}
);
You will notice that I am using the ObjectFactory.Initialize all my stuff. This is because StructureMapConfiguration has officially been deprecated and SHOULD not be used. Also pay close attention to the way I am using x.Scan(). In my initial testing I was having NO luck getting the auto wiring to work because I was doing this.
ObjectFactory.Initialize(
x =>
{
x.Scan( scanner =>
{
scanner.TheCallingAssembly();
} );
x.Scan( scanner =>
{
scanner.WithDefaultConventions();
} );
}
);
I am not 100% sure of the reason why, but I think it is because that each time Scan is called the list of internal 'scanners' gets reset (was walking through the code).
Also, keep in mind this will only auto wire your dependencies if the naming is as follows IFoo maps to Foo.
Hope this helps,
Till next time,
[----- Remember to check out DimeCasts.Net -----]