Hi,
I'm trying to understand why when I have a registered an IEnumerable
component, which I can resolve using a normal resolve method call, the
container will not satisfy another component's resolution call where
this second component has the same IEnumerable type dependency. I have
managed to get it to work using the DynamicParameters registration
helper method. I guess I could also get it to work using service
overrides.
Note I am using a factory method to create the IEnumerable component.
This simple example illustrates what I’m trying to understand, if you
remove the DynamicParameters usage in the Worker component
registration, its apples dependency will not be satisfied, even though
we could resolve the apples collection when doing so directly against
the container
Should the container not be able to satisfy the Worker apples
dependency without the help of DynamicParameters ?
Thanks in advance
Pat
var _container = new WindsorContainer();
_container.AddFacility("factorySupport", new
FactorySupportFacility());
_container.Register(
Component.For<AppleFactory>()
.Named("appleFactory"));
_container.Register(
Component.For<IEnumerable<Apple>>()
.Named("apples")
.LifeStyle.Transient
.UsingFactoryMethod(kernel =>
kernel.Resolve<AppleFactory>().GetAll()));
// If i don't include the DynamicParameters statement - Could not
resolve non-optional dependency for 'worker' (Worker). Parameter
'apples' type 'System.Collections.Generic.IEnumerable`1[[Apple,
ConsoleApplication1, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null]]'
_container.Register(
Component.For<Worker>()
.Named("worker")
.LifeStyle.Transient
.DynamicParameters((kernel, parameters) => { parameters["apples"] =
(kernel.Resolve<AppleFactory>()).GetAll(); })); // Could have just
used the apple factory directly here but i may want caching\logging
etc logic
var _apples = _container.Resolve<IEnumerable<Apple>>();
Console.WriteLine("Managed to resolve apples component, count = {0}",
_apples.Count());
Console.WriteLine("Now trying to resolve a worker which has an apples
dependancy which fails ");
var _worker = _container.Resolve<Worker>();
_worker.DoIt();
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en.