At present we use StructureMap v2.6 for our dependency injection and our setup is like this:
In the Application_Start we have:
DependencyResolver.SetResolver(new StructureMapDependencyResolver(IoC.Initialize()));
And the Initialize method is implemented like this:
public static IContainer Initialize() {
ObjectFactory.Initialize(x => {
x.Scan(scan => { scan.TheCallingAssembly(); scan.WithDefaultConventions(); });
x.For<IFoo>().Use(() => new Foo());
});
return ObjectFactory.Container;
}
}
Throughout our code we have several places that use ObjectFactory.GetInstance<IFoo>()
rather than using constructor injection. With v3 of StructureMap this has been marked as obsolete, so my question is how do we achieve the same thing with the latest version.