How can I implement Ninject .InSingletonScope() when using Unity IoC

别来无恙 提交于 2019-12-04 18:44:35

Unity uses the concept of LifeTimeManager's.. it comes with what is essentially a Singleton LifeTimeManager called ContainerControlledLifetimeManager. You would use it as below:

container.RegisterType<RepositoryFactories>(new ContainerControlledLifetimeManager(), /* other params */);

I'm unsure if you are asking what a Singleton is or not in your question:

also what does it mean "InSingletonScope()" ?

In the context of an IoC container such as Ninject and Unity, a Singleton is an object that is the same each time you request it. In your example, every time you ask your container to resolve a RepositoryFactories object.. it will always be the same object; not a new instance.

According to this you should use ContainerControlledLifetimeManager. Your registration will be:

container.RegisterType<RepositoryFactories>(new ContainerControlledLifetimeManager())
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!