认识一般主机的注入windows service
使用topself,因为我太蠢了,所以经常会1064或者是1053,最近花了1-2天才搞清楚在使用topself的时候应该怎么写。
Microsoft.Extensions.Hosting.IHost,
HostFactory.Run(x =>
{
x.Service<IHost>(s =>
{
s.ConstructUsing(() => Start00(fileroot, args, Log.Logger).Build());
s.WhenStarted(service =>
{
service.Start();//主机同步调用
});
s.WhenStopped(async service =>
{
await service.StopAsync();
});
});
//x.Service(s => new MainSiloServiceControl(fileroot, Log.Logger,args));
//x.Service<HYWServiceControl>();
x.EnableServiceRecovery(r => r.RestartService(TimeSpan.FromMinutes(1)));
x.RunAsLocalSystem();
x.SetDisplayName("路径测试员V2");
x.SetServiceName("路径测试员V2");
x.RunAsLocalService();
x.StartAutomaticallyDelayed();
});
见使用orleans的通用主机的例子。主要是为了看asp.net core是怎么配置的。
var host = new HostBuilder()
.ConfigureWebHostDefaults(webBuilder =>
{
// Configure ASP.NET Core
webBuilder.UseStartup<Startup>();
})
.UseOrleans(siloBuilder =>
{
// Configure Orleans
siloBuilder.UseLocalHostClustering();
})
.ConfigureLogging(logging =>
{
/* Configure cross-cutting concerns such as logging */
})
.ConfigureServices(services =>
{
/* Configure shared services */
})
.UseConsoleLifetime()
.Build();
// Start the host and wait for it to stop.
await host.RunAsync();
蠢人记录