Public class Program
{
Public static void Main (string [] args)
{
CreateWebHostBuilder (args);
}
Public static void CreateWebHostBuilder (string [] args)
{
Var configuration=new ConfigurationBuilder (). SetBasePath (Environment. CurrentDirectory)
. AddJsonFile (" host. Json ")
The Build ();
IWebHost host=to WebHost. CreateDefaultBuilder (args) UseUrls (configuration [" url "])
. UseStartup(). The Build ();
ApplicationEngine. StartEngine ();
The host. The Run ();
}
}
Public class ApplicationEngine
{
Private static ApplicationEngine _uniqueEngine;
Private ApplicationEngine () {
}
Public static int StartEngine ()
{
If (_uniqueEngine==null)
{
The lock (instanceObjectLock)
{
If (_uniqueEngine==null)
{
_uniqueEngine=new ApplicationEngine ();
}
}
}
return 0;
}
Public static ApplicationEngine Instance
{
The get
{
Return _uniqueEngine;
}
}
Subsequent access to the Instance is empty
CodePudding user response:
The breakpoint with a minute _uniqueEngine be new static should not be releasedCodePudding user response:
Well, we can't say no, we just want to say, when you make sure you visit he must have finished the StartEngine??Since in netcore discussion question, of course, we said that, although you so that we can't say wrong, can only say that if the netcore, his nature writing is
Public class ApplicationEngine: if you want to initialize the first please inheritance Ihostservice
{
}
To WebHost. CreateDefaultBuilder (args)
ConfigureServices (p=& gt;
{
P.A ddSingleton
//if you want to have the initialization, and to ensure the initialization process, combined with
P.A ddHoesedService (p=& gt; P.g etService
})
Behind you should be, how to control access to him, you should understand
CodePudding user response:
Not have injected directly into the singletonServices. AddSingleton<>
CodePudding user response:
InstanceObjectLock? Did not see the statementSince then use the.net core, the Singleton can be passed di di to statement
CodePudding user response:
Still want to mention a mouth, you all of this with the netcore, also need not di singleton, stem whatCodePudding user response:
How to obtain the integralCodePudding user response:
Don't understand. Netcore, take a look