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));
}

2 Answers 2

3

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

See this for details and example.

2

The following should to it

container.Register(
    Component.For(typeof(IFoo<>))
      .ImplementedBy(typeof(Foo<>))
);
1
  • 1
    thx but ... I am not interested in the type Foo<>, I am registering the type that is returned from the MakeGenericType method Jul 23, 2013 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.