Does Castle Windsor have a Static Class Similar to StructureMap's ObjectFactory?
I am currently making the move from StructureMap to Castle Windsor.
Using StructureMap, you can bootstrap the framework in one central location, and then call ObjectFactory.GetInstance anywhere in your code to grab an instance using that configuration. So conceptually there is a single container that you configure,开发者_如何学C and calls to the ObjectFactory use that container.
In the tutorials I've seen for Windsor, the container instance is always created explicitly, and resolution happens via the instance of that container. Is this just a difference in approaches between the two frameworks?
Assuming that's the case, what is the recommended way of handling cases where resolution needs to happen separately from configuration?
(Ideally, a single Resolve() call can be made after the configuration code, and no other references to the container will exist; however, there ARE cases where this isn't possible, like when working with a legacy codebase.)
No, it does not. And will not. If you're coming from Structure Map to Castle Windsor, read this.
re: how to pull at a later point w/o static locator see this.
I am not familiar with Windsor, but if it does not already have its own static facade class, it should be trivial to create your own. Create a static class with a static property that holds the configured container. Add a static method that resolves instances from that container. That is exactly what ObjectFactory does. StructureMap has a Container object that does all the real work - ObjectFactory is just a convenience wrapper.
If you really really need this, use CommonServiceLocator. It has adapters to all major IoC containers.
精彩评论