50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
|
using Microsoft.AspNetCore.Builder;
|
||
|
using Microsoft.Extensions.DependencyInjection;
|
||
|
|
||
|
using GameLibrary.Data;
|
||
|
using GameLibrary.Repositories;
|
||
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
||
|
namespace GameLibrary
|
||
|
{
|
||
|
public class Program
|
||
|
{
|
||
|
public static void Main(string[] args)
|
||
|
{
|
||
|
var builder = WebApplication.CreateBuilder(args);
|
||
|
|
||
|
builder.Services.AddDbContext<GameContext>();
|
||
|
|
||
|
builder.Services.AddScoped<IGameRepository, GameRepository>();
|
||
|
|
||
|
builder.Services.AddControllers();
|
||
|
builder.Services.AddCors(options =>
|
||
|
{
|
||
|
options.AddPolicy("AllowAllOrigins",
|
||
|
builder =>
|
||
|
{
|
||
|
builder.AllowAnyOrigin()
|
||
|
.AllowAnyMethod()
|
||
|
.AllowAnyHeader();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
var app = builder.Build();
|
||
|
|
||
|
app.UseCors("AllowAllOrigins");
|
||
|
|
||
|
app.UseHttpsRedirection();
|
||
|
app.UseAuthorization();
|
||
|
app.MapControllers();
|
||
|
|
||
|
using (var scope = app.Services.CreateScope())
|
||
|
{
|
||
|
var dbContext = scope.ServiceProvider.GetRequiredService<GameContext>();
|
||
|
dbContext.Database.EnsureCreated();
|
||
|
}
|
||
|
|
||
|
app.Run();
|
||
|
}
|
||
|
}
|
||
|
}
|