.net - 解决所有不使用名称

标签 .net unity-container

我得到了一个名为 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/

相关文章:

.net - 阻止 .NET 代码调用特定方法?

c# - 如何在 MVC 验证属性中使用 Unity IoC?

c# - 将工作单元注入(inject)存储库构造函数

.net - 统一容器: use ContainerControlledLifetimeManager by default for "Resolve" method group

c# - 来自程序集的 WPF 自定义 FontFamily?

c# - 在绑定(bind)源中复制记录

c# - 使用哪个隔离级别来防止读取数据?

.net - 创建不受 Windows 任务栏遮挡的窗体的正确方法是什么?

c# - 在 MVC 4 应用程序中使用 Unity 和 Entity Framework 的最佳实践是什么

unity-container - Unity 中的 ResolvedParameter。有人可以解释什么时候使用它吗?