-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
59 lines (43 loc) · 1.66 KB
/
Copy pathProgram.cs
File metadata and controls
59 lines (43 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using Microsoft.EntityFrameworkCore;
using Web.Data;
using Web.Models;
var builder = WebApplication.CreateBuilder(args);
var MyAllowSpecificOrigins = "AllowSpecificOrigin";
var allowedOrigins = builder.Configuration.GetSection("CorsSettings:AllowedOrigins").Get<string[]>();
// Add CORS services
builder.Services.AddCors(options =>
{
options.AddPolicy(MyAllowSpecificOrigins, policy =>
{
policy.WithOrigins(allowedOrigins)
.SetIsOriginAllowedToAllowWildcardSubdomains()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
//Warning, if you change DB type you may need to go to the DB context and update the case insensitivity column settings
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.Configure<PagingSettings>(builder.Configuration.GetSection("PagingSettings"));
builder.Services.AddProblemDetails();
builder.Services.AddScoped<ICustomers, Customers>();
builder.Services.AddScoped<IDiscounts, Discounts>();
builder.Services.AddScoped<IProducts, Products>();
builder.Services.AddScoped<ISales, Sales>();
builder.Services.AddScoped<ISalesPersons, SalesPersons>();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.UseExceptionHandler();
app.UseCors(MyAllowSpecificOrigins);
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();