63 lines
2.0 KiB
C#
63 lines
2.0 KiB
C#
using Microsoft.EntityFrameworkCore;
|
||
using PizzaExpress.Data;
|
||
|
||
namespace PizzaExpress
|
||
{
|
||
public class Program
|
||
{
|
||
public static void Main(string[] args)
|
||
{
|
||
var MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
|
||
var builder = WebApplication.CreateBuilder(args);
|
||
|
||
var allowedOrigins = builder.Configuration.GetSection("Cors:AllowedOrigins").Get<string[]>();
|
||
|
||
builder.Services.AddCors(options =>
|
||
{
|
||
options.AddPolicy(name: MyAllowSpecificOrigins,
|
||
policy =>
|
||
{
|
||
policy.WithOrigins(allowedOrigins)
|
||
.AllowAnyMethod()
|
||
.AllowAnyHeader()
|
||
.AllowCredentials();
|
||
});
|
||
});
|
||
|
||
|
||
// Add services to the container.
|
||
|
||
builder.Services.AddControllers()
|
||
.AddXmlSerializerFormatters();
|
||
|
||
// DB in memory perch<63> siamo froci
|
||
builder.Services.AddDbContext<PizzaContext>(opt =>
|
||
opt.UseInMemoryDatabase("dbpizze"));
|
||
|
||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||
builder.Services.AddEndpointsApiExplorer();
|
||
builder.Services.AddSwaggerGen();
|
||
|
||
var app = builder.Build();
|
||
|
||
using (var porcoidddioooo = app.Services.CreateScope())
|
||
{
|
||
var ctx = porcoidddioooo.ServiceProvider.GetRequiredService<PizzaContext>();
|
||
SeedData.Initialize(ctx);
|
||
}
|
||
|
||
app.UseSwagger();
|
||
app.UseSwaggerUI();
|
||
|
||
app.UseHttpsRedirection();
|
||
app.UseCors(MyAllowSpecificOrigins);
|
||
app.UseAuthorization();
|
||
|
||
|
||
app.MapControllers();
|
||
|
||
app.Run();
|
||
}
|
||
}
|
||
}
|