How are classes marked as singleton are initialized? Which scope do they use to be created?
Thanks in advance
7 Answer(s)
-
0
I recommend you check this article https://medium.com/volosoft/asp-net-core-dependency-injection-best-practices-tips-tricks-c6e9c67f9d96
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
@mailming I understand how DI works. What I am asking how are they being initialized in abp?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
They are initialized by the DI container, and abp uses [Windsor] (https://github.com/castleproject/Windsor).
Singleton components will only produce a single instance that is bound to the container. The instance will be created the first time someone requests it, and subsequently reused every time it's needed
Abp provides the IShouldInitialize interface. https://aspnetboilerplate.com/Pages/Documents/Dependency-Injection#ishouldinitialize-interface
Dependency injection containers can also use factory to create components.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
The instance will be created the first time someone requests it, and subsequently reused every time it's neededTake as example the EntityCache which is a singleton. It is using the dbcontext to get the entity from database if I am not mistaked. The first request that comes in the controller that uses an EntityCache is gonna use the dbcontext that was created for the first request. Is that right?Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
EntityCachenot a singleton service.SettingManageris a singleton service.It's usually the first request, but it will be created if you use it before requesting it, then reuse it. For example, call it when the application starts.
What problem have you encountered?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Where can I call it?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0

