DocSpace-buildtools/common/services/ASC.Notify/Program.cs

65 lines
2.6 KiB
C#
Raw Normal View History

2019-07-29 09:15:48 +00:00
using System.IO;
using System.Threading.Tasks;
using ASC.Common.DependencyInjection;
using ASC.Notify.Config;
using ASC.Web.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace ASC.Notify
{
public class Program
{
public static async Task Main(string[] args)
{
var host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostContext, config) =>
{
var buided = config.Build();
var path = buided["pathToConf"];
if (!Path.IsPathRooted(path))
{
path = Path.GetFullPath(Path.Combine(hostContext.HostingEnvironment.ContentRootPath, path));
}
config.SetBasePath(path);
2019-09-25 12:55:35 +00:00
var env = hostContext.Configuration.GetValue("ENVIRONMENT", "Production");
2019-07-29 09:15:48 +00:00
config
.AddJsonFile("appsettings.json")
2019-09-25 12:49:21 +00:00
.AddJsonFile($"appsettings.{env}.json", true)
2019-07-29 09:15:48 +00:00
.AddJsonFile("autofac.json")
.AddJsonFile("storage.json")
.AddJsonFile("notify.json")
2019-08-23 12:49:23 +00:00
.AddJsonFile("kafka.json")
2019-09-25 12:49:21 +00:00
.AddJsonFile($"kafka.{env}.json", true);
2019-07-29 09:15:48 +00:00
})
.ConfigureServices((hostContext, services) =>
{
2019-08-01 08:47:15 +00:00
services.AddAutofac(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath);
services.AddWebItemManager();
2019-07-29 09:15:48 +00:00
var serviceProvider = services.BuildServiceProvider();
2019-10-09 16:08:37 +00:00
var c = hostContext.Configuration.GetSetting<NotifyServiceCfg>("notify");
2019-07-29 09:15:48 +00:00
c.Init();
services.AddSingleton(c);
services.AddSingleton<DbWorker>();
services.AddSingleton<NotifyCleaner>();
services.AddSingleton<NotifySender>();
2019-08-01 08:47:15 +00:00
services.AddSingleton<NotifyService>();
2019-07-29 09:15:48 +00:00
services.AddHostedService<NotifyServiceLauncher>();
})
.UseConsoleLifetime()
.Build();
using (host)
{
// Start the host
await host.StartAsync();
// Wait for the host to shutdown
await host.WaitForShutdownAsync();
}
}
}
}