YPS-Beer/backend/YPS.Beer/Program.cs

45 lines
1.2 KiB
C#
Raw Normal View History

2023-12-07 00:20:59 +00:00
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using YPS.Beer.Data;
using YPS.Beer.Models;
using YPS.Beer.Services;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddControllers();
builder.Services.AddHttpClient<IPunkService, PunkService>();
builder.Services.AddScoped<IBeerService, BeerService>();
builder.Services.AddDbContext<BeerContext>(options => options.UseInMemoryDatabase("yps-beer"));
builder.Services.AddIdentityCore<User>()
.AddEntityFrameworkStores<BeerContext>()
.AddApiEndpoints();
builder.Services.AddAuthentication(IdentityConstants.ApplicationScheme)
.AddBearerToken(IdentityConstants.BearerScheme)
.AddApplicationCookie();
builder.Services.AddAuthorizationBuilder();
builder.Services.AddCors();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.UseCors(cors => cors.AllowAnyHeader().AllowAnyMethod().SetIsOriginAllowed(_ => true).AllowCredentials());
}
app.UseHttpsRedirection();
app.MapControllers();
app.MapIdentityApi<User>();
app.Run();