Example #1
0
        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .ConfigureServices((hostContext, services) =>
        {
            var configBuilder = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: false);

            IConfiguration config = configBuilder.Build();

            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(config.GetConnectionString("AppDbContext")
                                                                              ), ServiceLifetime.Transient, ServiceLifetime.Scoped);

            services.AddSingleton(config);

            var samplingWindow = new SamplingWindowConfiguration()
            {
                StartSampleDateTime = DateTime.Now,
                EndSampleDateTime   = DateTime.Now
            };

            services.AddTransient <ICustomDbService, CustomDBService>();
            services.AddTransient <ICustomEventHubSenderService, CustomEventHubSenderService>();

            services.AddSingleton(samplingWindow);

            services.AddHostedService <LoginEventJobService>();
        });
Example #2
0
 public CustomDBService(
     IConfiguration configuration,
     ILogger <CustomDBService> logger,
     ApplicationDbContext db,
     SamplingWindowConfiguration samplingWindowConfiguration)
 {
     this._logger = logger;
     this._db     = db;
     this._samplingWindowConfiguration = samplingWindowConfiguration;
 }