Example #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddDefaultPolicy(builder =>
                {
                    builder.AllowAnyOrigin();
                    builder.AllowAnyMethod();
                    builder.AllowAnyHeader();
                });
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddSingleton(CreateMapper());

            services.AddSingleton(x => CreateSchedulerConfig());

            services.AddSingleton(x => CreateLoggerConfig().CreateLogger());

            services.AddSingleton<ISchedulingService, SchedulingService>();

            services.AddDbContext<SerilogContext>(options =>
            {
                options.UseSqlServer(ConfigurationLoader.GetLogsDbConnectionString(Configuration));
            }, ServiceLifetime.Singleton);

            services.AddSingleton<ILogQueryService, LogQueryService>();

            var schedulerService = services.BuildServiceProvider().GetService<ISchedulingService>();
            schedulerService.StartScheduler();
        }