Exemplo n.º 1
0
        public static void AddDatabaseRegistration(this IServiceCollection services, ForecastingConfiguration config, string environmentName)
        {
            if (environmentName.Equals("LOCAL", StringComparison.CurrentCultureIgnoreCase))
            {
                services.AddDbContext <ForecastingDataContext>(options => options.UseSqlServer(config.ConnectionString), ServiceLifetime.Transient);
            }
            else
            {
                services.AddSingleton(new AzureServiceTokenProvider());
                services.AddDbContext <ForecastingDataContext>(ServiceLifetime.Transient);
            }

            services.AddTransient <IForecastingDataContext, ForecastingDataContext>(provider => provider.GetService <ForecastingDataContext>());
            services.AddTransient(provider => new Lazy <ForecastingDataContext>(provider.GetService <ForecastingDataContext>()));
        }
Exemplo n.º 2
0
 public ForecastingDataContext(IOptions <ForecastingConfiguration> config, DbContextOptions options, AzureServiceTokenProvider azureServiceTokenProvider) : base(options)
 {
     _configuration             = config.Value;
     _azureServiceTokenProvider = azureServiceTokenProvider;
 }