Unity and Eager Singleton

Good morning, I would like to get a singleton in Unity, this singleton needs to be entered so that the methods RegisterInstancethemselves do not. The only thing I can think of is to have something like this in the configuration module:

container.RegisterType<Singletion, Singletion>(new ContainerControlledLigetimeManager());
container.Resolve<Singletion>();

but this seam indulges me a little.

+3
source share
1 answer

My best suggestion is to implement a custom class LifetimeManager. Unfortunately, I cannot find useful documentation on how to do this.

+1
source

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


All Articles