c# - Castle Windsor - Register all interfaces with factory method -


i have number of interfaces:

  • ifirstprovider
  • isecondprovider
  • ithirdprovider
  • etc..

i'm trying register these interfaces use factory method instance:

container.register     (           alltypes             .fromthisassembly()             .where(t => t.isinterface && t.name.endswith("provider"))             .configure(c => c.usingfactorymethod(f => f.resolve<dictionaryadapterfactory>().getadapter<object>(c.servicetype, session))     ); 

but doesn't seem work. instead, have use for loop register these interfaces:

list<type> providers = new list<type>     (         assembly             .getexecutingassembly()             .gettypes()             .where(x => x.isinterface && x.name.endswith("provider"))     );  foreach (type provider in providers) {     type temp = provider;      container.register         (             component                 .for(temp)                 .usingfactorymethod(f => f.resolve<dictionaryadapterfactory>().getadapter<object>(temp, session))         ); } 

is there better way register these interfaces besides using for loop?

there's no better built in way in windsor < 3.0

as of windsor 3, can using types, instead of alltypes.

alltypes means all non abstract classes

types means all types.

yes, while suck , counterintuitive, since alltypes came first, couldn't change existing behavior maintain backward compatibility. maintain sanity recommended use classes instead of alltypes, you'll end registering either classses classes , types cases 1 in question.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -