c# - Why can my WindsorContainer not resolve IWindsorContainer? -
this example not using best practice using iservicelocator wrap container has me bit baffled.
i thought windsorcontainer automatically resolve iwindsorcontainer?
var container = new windsorcontainer(); container.register(component.for<ineedwindsorcontainer>() .implementedby<givemewindsorcontainer>() .lifestyle.singleton);
implementation of ineedwindsorcontainer:
public class givemewindsorcontainer : ineedwindsorcontainer { iwindsorcontainer _container; public givemewindsorcontainer(iwindsorcontainer container) { _container = container; } }
this not work, because windsorcontainer not know how resolve iwindsorcontainer!
of course immediate solution came was:
var container = new windsorcontainer(); container.register( component.for<iwindsorcontainer>() .instance(container) .lifestyle.singleton, component.for<ineedwindsorcontainer>() .implementedby<givemewindsorcontainer>() .lifestyle.singleton);
however seems bit odd me, doing wrong?
windsor can automatically resolve ikernel (the container core, has of functions you'll need).
as said yourself, it's not practice pass container itself. of times should use factory, perhaps through typed factory facility.
Comments
Post a Comment