// 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.AddPolicy("AllowAll", builder => builder .AllowAnyMethod() .AllowAnyOrigin() .AllowAnyHeader())); RuntimeStartup.ConfigureServices(services, Configuration, (options, connectionStringName) => options.UseNpgsql(Configuration.GetConnectionString(connectionStringName))); services.RegisterEfCore(); services.AddControllers() .AddNewtonsoftJson(options => { options.UseMemberCasing(); }) .AddJsonOptions(jsonOptions => { jsonOptions.JsonSerializerOptions.PropertyNamingPolicy = null; }); services.AddAuthentication("Bearer") .AddIdentityServerAuthentication(options => { options.Authority = Configuration.GetSection("AuthAuthority").Get <string>(); options.RequireHttpsMetadata = false; }); }
public void ConfigureServices(IServiceCollection services) { services.AddCors(options => options.AddPolicy("AllowAll", builder => builder .AllowAnyMethod() .AllowAnyOrigin() .AllowAnyHeader())); services.AddDbContext <MetadataDbContext>(options => { var provider = Configuration.GetSection("EfProvider").Get <string>(); switch (provider) { case "MySql": options.UseMySql( Configuration.GetConnectionString("Engine_MySql")); return; case "SqlServer": options.UseSqlServer( Configuration.GetConnectionString("Engine_SqlServer")); return; default: throw new NotImplementedException($"The provider {provider} is not implemented yet."); } }); RuntimeStartup.ConfigureServices(services, Configuration); services.RegisterEfCore(); services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1); services.AddAuthentication("Bearer") .AddIdentityServerAuthentication(options => { options.Authority = "http://localhost:5001"; options.RequireHttpsMetadata = false; }); }