I'm starting using Windsor, and I want to understand when should I use container
and when kernel
. E.g.
var c = new WindsorContainer();
c.Register(Component.For<ITt>().ImplementedBy<Tt>());
var tt = c.Resolve<ITt>();
Everything is fine and everything works,
but here is also c.kernel
that can do the same, what for?
var c = new WindsorConatiner();
c.kernel.Register(Component.For<ITt>().ImplementedBy<Tt>());
var tt = c.kernel.Resolve<ITt>();
Honestly I don't well understand is there any difference between "Container" and "Kernel" term. In my head it sounds like two names of the same thing in different IoC Libraries?
P.S. I read this post but still can't understand what for leave two implementations of one functionality here?
Update: Just found in my code such row
c.Kernel.Resolver.AddSubResolver(new ArrayResolver(c.Kernel));
What reason was to do it through Kernel? I completely lost
They're mostly equivalent today, but at first the IKernel and the IWindsorContainer were living in separate assemblies, with the Windsor container wrapping the kernel. Both were merged at some point but were kept alive to ensure backwards compatibility for users who may have used one or another.
Since the merge occured at version 2.5 (as discussed in the linked post) it is reasonable to assume there was some non negligible number of users who may have worked on one interface or the other, hence the cruft you see now.
Looking into the code you can see that almost all code from the windsor container calls the kernel internally, with some behavior added for child containers functionality, another option that remains from the past and is not necessarily useful
To those who though I’m seriously going to remove support for nested containers rest assured this is not going to happen. I still think this could be a viable option and I wanted to throw it into the air, but its become such a core feature of each IoC container, that Windsor would look crippled if it didn’t have it, regardless of whether or not it’d be actually needed.
In the end, I'd recommend using the container; it wraps the kernel and is the official point of entry for managing your application (for example there is no Install
method on the kernel)
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