// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { corsConfiguration = new CorsPolicyConfiguration(); Configuration.Bind("CorsPolicies", corsConfiguration); var corsPolicy = corsConfiguration.Policies.First(p => p.PolicyName.Equals(corsConfiguration.DefaultPolicyName)); services.AddCors(options => { options.AddDefaultPolicy( builder => { builder.WithOrigins(corsPolicy.Origins); builder.AllowAnyHeader(); }); }); services.AddDbContext <StockTraderContext>(opt => opt.UseSqlServer(Configuration.GetConnectionString("StockTrader"))); services.AddControllers(); services.AddScoped <IStockDataRepo, SqlStockDataRepo>(); services.AddScoped <IStockDownloader, YahooFinanceDownloader>(); services.AddScoped <IApproachRepo, SqlApproachRepo>(); services.AddScoped <IRunRepo, SqlRunRepo>(); services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); }
private static void AddPolicy(CorsPolicyBuilder policyBuilder, CorsPolicyConfiguration policy) { if (policy.Origins.Length == 0) { throw new System.ArgumentException(); } policyBuilder.WithOrigins(policy.Origins); // Configure methods if (policy.Methods.Length == 0) { policyBuilder.AllowAnyMethod(); } else { policyBuilder.WithMethods(policy.Methods); } // Configure headers if (policy.Headers.Length == 0) { policyBuilder.AllowAnyHeader(); } else { policyBuilder.WithHeaders(policy.Headers); } //Configure credentials if (policy.AllowCredentials) { policyBuilder.AllowCredentials(); } else { policyBuilder.DisallowCredentials(); } }