3

Is there a fluent way of writing the following:

var someTypes = GetType()
    .Assembly
    .GetTypes()
    .Where(x => someFilter == true);

foreach(var someType in someTypes)
{
    var genericInterface = typeof(IFoo<>).MakeGenericType(someType);

    var genericImplementation = typeof(Foo<>).MakeGenericType(someType);

    container.Register(
       Component.For(genericInterface)
            .ImplementedBy(genericImplementation));
}
Steven
  • 166,672
  • 24
  • 332
  • 435
David Perlman
  • 1,460
  • 1
  • 12
  • 32

2 Answers2

3

a IGenericServiceStrategy is what you're after (on top of what @maxlego said, which is correct)

See this for details and example.

Krzysztof Kozmic
  • 27,267
  • 12
  • 73
  • 115
2

The following should to it

container.Register(
    Component.For(typeof(IFoo<>))
      .ImplementedBy(typeof(Foo<>))
);
maxlego
  • 4,864
  • 3
  • 31
  • 38
  • 1
    thx but ... I am not interested in the type Foo<>, I am registering the type that is returned from the MakeGenericType method – David Perlman Jul 23 '13 at 08:23