// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc(opts => { opts.EnableEndpointRouting = false; opts.InputFormatters.RemoveType <SystemTextJsonInputFormatter>(); opts.InputFormatters.Add(new TextUniversalInputFormatter()); }); var dataOptions = new DataOptions(); Configuration.Bind("Data", dataOptions); services.AddSingleton(dataOptions); services.AddHttpContextAccessor(); services.AddScoped <ConnectionService>(); services.AddDbContext <NpgSqlDpcModelDataContext>(options => options.UseNpgsql(dataOptions.DesignConnectionString)); services.AddDbContext <SqlServerDpcModelDataContext>(options => options.UseSqlServer(dataOptions.DesignConnectionString)); services.AddScoped(sp => { var customer = sp.GetRequiredService <ConnectionService>().GetCustomer().Result; if (customer.DatabaseType == DatabaseType.Postgres) { return(GetNpgSqlDpcModelDataContext(customer.ConnectionString)); } return(GetSqlServerDpcModelDataContext(customer.ConnectionString)); }); services.AddScoped <ILogger>(logger => new NLogLogger("NLog.config")); services.AddScoped(typeof(IDpcProductService), typeof(DpcProductService)); services.AddScoped(typeof(IDpcService), typeof(DpcProductService)); services.Configure <IntegrationProperties>(Configuration.GetSection("Integration")); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "DPC Front API", Version = "v1", Description = "This API gives access to reference fronts" }); }); }
public ConnectionService(IHttpContextAccessor httpContextAccessor, DataOptions options, IOptions <IntegrationProperties> intOptions) { _context = httpContextAccessor.HttpContext; _options = options; _intOptions = intOptions.Value; }