默认情况下,LifetimeManager的单经理(ContainerControlledLifetimeManager)? [英] Default the LifetimeManager to the singleton manager (ContainerControlledLifetimeManager)?
问题描述
我使用的是统一的IoC容器做的依赖注入。我设计我的系统周围,至少为一个单一的分辨率,所有类型的层次结构将表现为单件,也就是说,该层次结构内相同类型的分辨率将导致相同的实例的想法。
I'm using a Unity IoC container to do Dependency Injection. I designed my system around the idea that, at least for a single resolution, all types in the hierarchy would behave as singletons, that is, same type resolutions within that hierarchy would lead to the same instances.
不过,我(一)希望扫描我的程序集找到的类型和(b)并不想明确地告诉单位,每一个类型是在配置文件中注册类型时要解决的是一个单例。
However, I (a) would like to scan my assemblies to find types and (b) don't want to explicitly tell unity that every type is to be resolved as a singleton when registering types in the configuration file.
那么,有没有一种方法来告诉团结当作单身?所有注册的映射
推荐答案
您可以在解析管道的寿命阶段,并在其中始终使用ContainerControlledLifetimeManager实例添加一个统一的扩展。
You could add a Unity extension at the 'Lifetime' stage of the resolution pipeline and in it always use a ContainerControlledLifetimeManager instance.
编辑:其实这个帖子有确切的例子:
In fact this post has the exact example:
的https://unity.$c$cplex.com/discussions/352179
这篇关于默认情况下,LifetimeManager的单经理(ContainerControlledLifetimeManager)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!