我得到了一个名为 IStartable
的接口(interface),它由多个实体实现。所有这些都使用 RegisterType
注册到 UnityContainer
而没有名称。
我想要实现的是:
_container.ResolveAll<IStartable>().ForEach(startable => startable.Start());
//application lifetime
_container.ResolveAll<IStartable>().ForEach(startable => startable.Stop());
我怎样才能做到这一点而不必为所有注册命名?
最佳答案
据我所知,你不能。您需要命名所有注册。
的确如此,参见 here :
5: If you want to create more than one registration using the same registered type, you can create a named (non-default) registration by specifying a name as a parameter [...]
关于.net - 解决所有不使用名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4458736/