0
votes

I am new to IoC and especially castle windsor. Can someone explain to me the differences between part1 and part2? My understanding is part1 is where you register components and part2 is a factory where it creates object. I am not sure what component means in this context. I read some of the documentation http://docs.castleproject.org/ but cannot seem to find where it explains these 2 in detail.

container.Register
(
//part1
AllTypes.FromAssemblyContaining<AnotherClass>()
.BasedOn<ISomething>()
.WithService.DefaultInterfaces()
.WithService.Self(),
//part2
Component.For<ISomething>().ImplementedBy<Something>()
);
1

1 Answers

1
votes

Result is the same: registering component(s) in the container.

The first approch allows to register multiple components matching a set of criteria. In your case you are registering all classes implementing ISomenthing contained in the assemby which contains AnotherClass, then using With... You are making your components resolvable through the DefaultInterfaces (read the wiki for details) or through the type itself.

The second approach is more straight forward... You are registering only one component which Will be resolvable by its ISomenthing interface only