Solve everything without using names

I got an interface called IStartablethat is implemented by several concretes. All are registered on UnityContainer, using RegisterTypewithout a name.

I am trying to achieve:

_container.ResolveAll<IStartable>().ForEach(startable => startable.Start());
//application lifetime
_container.ResolveAll<IStartable>().ForEach(startable => startable.Stop());

How can I achieve this without naming all registrations?

+3
source share
1 answer

As far as I know, you cannot. You need to specify all registrations.

In fact, see here :

5: If you want to create more than one registration using the same registered type, you can create a name (not the default) by registering by specifying the name as a parameter [...]

+5
source

Source: https://habr.com/ru/post/1780626/


All Articles