What is the difference between Castle Windsor "Container" and "Kernel"?
Asked Answered
G

1

10

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

Groundspeed answered 14/8, 2014 at 7:48 Comment(1)
The way I see it , it is just a overload which can give you more access to the internal of winddsor.Pyromagnetic
O
15

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 seri­ously going to remove sup­port for nested con­tain­ers rest assured this is not going to hap­pen. I still think this could be a viable option and I wanted to throw it into the air, but its become such a core fea­ture of each IoC con­tainer, that Wind­sor would look crip­pled if it didn’t have it, regard­less of whether or not it’d be actu­ally 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)

Olander answered 14/8, 2014 at 8:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.