Looks like a job for a ISubDependencyResolver... On Aug 8, 7:31 am, Dennis <[EMAIL PROTECTED]> wrote: > I managed to find > something:http://weblogs.asp.net/bsimser/archive/2008/06/27/testing-castle-wind... > > This lead me to try this: > > public class Search<T> > { > private List<ISearchProvider<T>> Providers > { > get > { > List<ISearchProvider<T>> validProviders = new > List<ISearchProvider<T>>(); > var allSearchProviders = > IoC.Container.Kernel.GetAssignableHandlers(typeof(ISearchProvider<>)); > foreach (var handler in allSearchProviders) > { > var implementation = > handler.ComponentModel.Implementation; > Type genimpl; > try > { > genimpl = implementation.MakeGenericType(typeof > (T)); > } > catch(ArgumentException) > { > continue; > } > > validProviders.Add((ISearchProvider<T>)Activator.CreateInstance(genimpl)); > } > return validProviders; > } > } > ... > > } > > It isn't nice, but it works. > It doesn't use the IoC to instantiate the class though, not sure if > this is a problem or not. > > On Aug 8, 4:01 pm, Dennis <[EMAIL PROTECTED]> wrote: > > > I have a problem that I cannot figure out how to solve, so was hoping > > someone here had a good idea. > > > I have an interface ISearchProvider<T> and many implementations, e.g. > > these two: > > class P1Search<T> : ISearchProvider<T> where T : P1 > > class P2Search<T> : ISearchProvider<T> where T : P2 > > > What I want to do, is have a single class Search<K> that finds all the > > ISearchProviders<T> where typeof(T).IsAssignableFrom(typeof(K)) > > > I tried with the obvious: > > var allSearchProviders = IoC.ResolveAll<ISearchProvider<K>>(); > > but it tries to instantiate both implementations, which throws an > > exception due to the "where" clause of the implementation. > > > Don't have a clue how else to solve this problem. > > > I am sorry if this is something that has been asked before, I had no > > clue what to search for. So you are more than welcome to refer me to > > the documentation or another post :) > > > -- > > Dennis --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
