c# - Castle Windsor resolve array of generic interfaces -


i have assembly amount of implementations of same generic interface. register of them in 1 shot using following registration in windsor:

types    .fromassembly(assembly.getexecutingassembly())    .basedon(typeof(iquery<,>)) 

now array of registered implementations if try castle bombs:

container.resolveall(typeof (iquery<,>)) 

why?

@steven right, not possible resolve generic types without knowing types embed. there 2 ways sidestep problem

either have closed list of possible input , outputs types, on can iterate in order resolve specific combinations

for var type1 in possibletypes1     var type2 in possibletypes2         var list = container.resolveall(typeof(iquery<,>).makegenerictype(type1, type2) 

this not elegant can queries. i'd propose second alternative.

if want resolve queries, must have operation want call on them, or information out. if operation or information should exist inside base non-generic interface generic interface inherits from. let's want operation name, like:

public interface ibasequery {     string getoperationname(); // common operation  }  public interface iquery<in, out>: ibasequery { } 

you register iquery implementations against interfaces , resolve ibasequery call common implementation queries.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -