I have got a problem with StructureMap 4.0. When working with StructureMap 3.0, I use ObjectFactory to configure all instances and it's very easy to get instance through its own interface anywhere inside the solution. For example:
at the global.cs, I declare like below: ObjectFactory.Initialize(x => { x.For().Use(); }
at the other class, for instance, Family.cs, it's easy to get instance of Peson: var person = ObjectFactory.GetInstance();
However, I have got problem after updating StructureMap to 4.0. It uses Container instead of ObjectFactory and I don't find any way to get existing container.I mean this code is wrong var person = container.GetInstance();
If I declare Container as a static variable in global.cs then I can access it from Family.cs class. I don't like this way. I want Container work like ObjectFactory by fetching existing container that is declared in global.cs but I don't know how to do it.
The way to do this is to take IContainer
as a constructor argument in your class. See this for more info StructureMap
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With