(CORE) CORE (2022)

Notes about singleton service.

My current project now has 3 singleton services and I want small notice about this type of Net Core services.



First interesting experiment is create simple Singleton class in OOP meaning (with private constructor what protect to create another class instance and shared variable refer to instance) and try to use this class as Net Core singleton service, something like that:



This is not workable way because ASP.NET DI container forbid this way to create singleton.



This is interesting result - singleton class and singleton NET Core service is not related one to another entity.

So, correct way is class with public constructor visible from DI container.



We can delegate create exemplar of singleton service to DI container (line 62).



And moreover, in my case I want to use singleton service as BLL, as service over other controller function (not only for classes), therefore I must inject reference to other services in methods, not in constructor.



And main future to create singleton service - pay attention how I inject instance of singleton service to controller in order to avoid cross reference in DI container.



Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23
Link to this page: http://www.vb-net.com/SingletonService/Index.htm
<SITEMAP>  <MVC>  <ASP>  <NET>  <DATA>  <KIOSK>  <FLEX>  <SQL>  <NOTES>  <LINUX>  <MONO>  <FREEWARE>  <DOCS>  <ENG>  <CHAT ME>  <ABOUT ME>  < THANKS ME>