José
I did look at CollectionResolver, but that solves a different problem
than what I am trying to achieve. I will not have registered all the
apples in the container, I want to get the apples from the apple
factory and hence i have configured the apples component as transient
which allows me to use the factory method every time i need to satisfy
an apples dependency. This means the dependency collection is dynamic
and can change over time etc.
I have used a pretty simple example to illustrate, but i would expect
the problem is not uncommon i.e. a repository backed collection which
is a dependancy for another component ?


Thanks
Pat



On Jan 8, 12:09 pm, José F. Romaniello <[email protected]> wrote:
> There is a resolver for that, you can use:
> container.Kernel.Resolver.AddSubResolver(new
> CollectionResolver(container.Kernel, true));
>
> then you can register all your Apples as such, and inject
> IEnumerable<Apple>, Apple[], IList<Apple> or ICollection<Apple>
>
> (More info here:http://stw.castleproject.org/Windsor.Resolvers.ashx)
>
> So, you wouldn't need a factory or anything else.
>
> Maybe IEnumerable<T> are handled differently, not sure about this.
>
> 2011/1/8 pmcg <[email protected]>
>
> > 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]<castle-project-users%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/castle-project-users?hl=en.
>
>

-- 
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.

Reply via email to