1

In my project I have the interface IProcess and a lot of classes implementing this interface. I need to register all those implementations. The following code is working fine for me:

Container.Register(Component.For<IProcess>().Named("SampleProcess").ImplementedBy<SampleProcess>());
Container.Register(Component.For<IProcess>().Named("SampleProcess2").ImplementedBy<SampleProcess2>());

However using this approach for registering is tedious if I have a lot of implementations. Therefore I am looking for a registration method to register all implementations of IProcess in a given assembly by name. The name that should be used for the registration key is just the class name.

Can someone pls give me a hint where to look for?

marco birchler
  • 1,566
  • 2
  • 21
  • 45

1 Answers1

1

Sounds like a classic scenario for the convention registration API.

container.Register(
    Classes.FromThisAssembly()
        .BasedOn<IProcess>()
        .WithServiceBase()
        // and then if you *really* need to explicitly control naming
        .Configure(c => c.Named(c.Implementation.Name)
        )

Generally explicitly naming your components shouldn't be used, unless you have multiple components with the same implementation class, so just make sure you really need it.

Krzysztof Kozmic
  • 27,267
  • 12
  • 73
  • 115
  • 1
    Thank you Krzysztof! It was really this simple - I was playing around alot with the convention reg api but something was always missing. The line containing the name configuration was indeed not needed in my case. – marco birchler Mar 08 '19 at 06:42