Simpleinjector 3.0 does not support RegisterManyForOpenGeneric

So, I decided to upgrade my version of simpleinjector to 3.0, and suddenly I get a message:

'SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManyForOpenGeneric (SimpleInjector.Container, System.Type, params System.Reflection.Assembly [])' deprecated: 'This extension method has been removed. Use Container.Register (Type, IEnumerable) instead.

The documentation still has this method:

http://simpleinjector.readthedocs.org/en/latest/advanced.html

So I'm curious what the alternative is:

container.RegisterManyForOpenGeneric(typeof(IEventHandler<>), container.RegisterAll, typeof(IEventHandler<>).Assembly); 
+4
source share
1 answer

Ah .. after scratching my head for several hours, I understood that :

 container.RegisterCollection(typeof(IEventHandler<>), typeof(IEventHandler<>).Assembly); 

RegisterCollection also handles open generics. Perhaps it should be registered somewhere.

EDIT:

I realized in the new documentation, this code is not a direct translation from RegisterManyForOpenGeneric. All that was done was to solve my compilation, but it did not register my handlers, I just checked it today.

Additional information: No registration for type

This is the correct version:

 container.Register(typeof(IEventHandler<>), new[] { typeof(IEventHandler<>).Assembly }); 

Using RegisterCollection will require additional code changes (from the document):

Since we are registering a collection, we can no longer call container.GetInstance> (). Instead, instances can be obtained using the constructor argument IEnumerable> or by calling container.GetAllInstances> ().

What I have not done yet, and I really do not need to do this, since I do not have mixed open and non-generic ones. But I will explore this more in the future if I want to update my project.

+6
source

All Articles