Beispiel #1
0
        public static async Task Main(string[] args)
        {
            var host = Host.CreateDefaultBuilder(args)
                       .UseServiceProviderFactory(new AutofacServiceProviderFactory())
                       .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);
                var env = hostContext.Configuration.GetValue("ENVIRONMENT", "Production");
                config
                .AddJsonFile("appsettings.json")
                .AddJsonFile($"appsettings.{env}.json", true)
                .AddJsonFile($"appsettings.services.json", true)
                .AddJsonFile("storage.json")
                .AddJsonFile("notify.json")
                .AddJsonFile("kafka.json")
                .AddJsonFile($"kafka.{env}.json", true)
                .AddEnvironmentVariables()
                .AddCommandLine(args)
                .AddInMemoryCollection(new Dictionary <string, string>
                {
                    { "pathToConf", path }
                }
                                       );
            })
                       .ConfigureServices((hostContext, services) =>
            {
                services.AddMemoryCache();
                var diHelper = new DIHelper(services);
                diHelper.TryAdd(typeof(ICacheNotify <>), typeof(KafkaCache <>));
                LogNLogExtension.ConfigureLog(diHelper, "ASC.Notify", "ASC.Notify.Messages");
                services.AddHostedService <ServiceLauncher>();
                diHelper.TryAdd <ServiceLauncher>();
                NotifyConfigurationExtension.Register(diHelper);
                diHelper.TryAdd <EmailSenderSink>();
            })
                       .ConfigureContainer <ContainerBuilder>((context, builder) =>
            {
                builder.Register(context.Configuration, context.HostingEnvironment.ContentRootPath);
            })
                       .UseConsoleLifetime()
                       .Build();

            using (host)
            {
                // Start the host
                await host.StartAsync();

                // Wait for the host to shutdown
                await host.WaitForShutdownAsync();
            }
        }
Beispiel #2
0
        public override void ConfigureServices(IServiceCollection services)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            services.AddDistributedMemoryCache();

            base.ConfigureServices(services);

            DIHelper.TryAdd <CalendarController>();

            NotifyConfigurationExtension.Register(DIHelper);
        }
Beispiel #3
0
 public static IHostBuilder CreateHostBuilder(string[] args) =>
 Host.CreateDefaultBuilder(args)
 .UseSystemd()
 .UseWindowsService()
 .UseServiceProviderFactory(new AutofacServiceProviderFactory())
 .ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup <BaseWorkerStartup>())
 .ConfigureAppConfiguration((hostContext, config) =>
 {
     var buided = config.Build();
     var path   = buided["pathToConf"];
     if (!Path.IsPathRooted(path))
     {
         path = Path.GetFullPath(CrossPlatform.PathCombine(hostContext.HostingEnvironment.ContentRootPath, path));
     }
     config.SetBasePath(path);
     var env = hostContext.Configuration.GetValue("ENVIRONMENT", "Production");
     config
     .AddJsonFile("appsettings.json")
     .AddJsonFile($"appsettings.{env}.json", true)
     .AddJsonFile($"appsettings.services.json", true)
     .AddJsonFile("storage.json")
     .AddJsonFile("notify.json")
     .AddJsonFile($"notify.{env}.json", true)
     .AddJsonFile("kafka.json")
     .AddJsonFile($"kafka.{env}.json", true)
     .AddEnvironmentVariables()
     .AddCommandLine(args)
     .AddInMemoryCollection(new Dictionary <string, string>
     {
         { "pathToConf", path }
     }
                            );
 })
 .ConfigureServices((hostContext, services) =>
 {
     services.AddMemoryCache();
     var diHelper = new DIHelper(services);
     diHelper.TryAdd(typeof(ICacheNotify <>), typeof(KafkaCache <>));
     diHelper.RegisterProducts(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath);
     services.AddHostedService <ServiceLauncher>();
     diHelper.TryAdd <ServiceLauncher>();
     NotifyConfigurationExtension.Register(diHelper);
     diHelper.TryAdd <EmailSenderSink>();
 })
 .ConfigureContainer <ContainerBuilder>((context, builder) =>
 {
     builder.Register(context.Configuration);
 })
 .ConfigureNLogLogging();
Beispiel #4
0
        public override void ConfigureServices(IServiceCollection services)
        {
            base.ConfigureServices(services);

            DIHelper.AddDistributedTaskQueueService <BaseBackupProgressItem>(1);

            DIHelper.TryAdd <BackupProgressItem>();
            DIHelper.TryAdd <RestoreProgressItem>();
            DIHelper.TryAdd <TransferProgressItem>();

            DIHelper.TryAdd <BackupServiceLauncher>();
            DIHelper.TryAdd <BackupController>();
            NotifyConfigurationExtension.Register(DIHelper);

            services.AddHostedService <BackupServiceLauncher>();
        }