YPS-Beer/backend/YPS.Beer/Program.cs
2023-12-07 01:08:37 +00:00

57 lines
1.5 KiB
C#

using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using YPS.Beer.Configuration;
using YPS.Beer.Data;
using YPS.Beer.Models;
using YPS.Beer.Services;
var builder = WebApplication.CreateBuilder(args);
var punkServiceConfiguration = new PunkServiceConfiguration();
builder.Configuration.GetSection(PunkServiceConfiguration.ConfigurationSection).Bind(punkServiceConfiguration);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddControllers();
builder.Services.AddHttpClient<IPunkService, PunkService>()
.ConfigureHttpClient(client => client.BaseAddress = new Uri(punkServiceConfiguration.BaseUrl));
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(options =>
{
options.AddDefaultPolicy(policy => policy.WithOrigins("http://localhost:3000").AllowAnyMethod().AllowAnyHeader().AllowCredentials());
});
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseRouting();
app.UseHttpsRedirection();
app.UseCors();
app.UseAuthorization();
app.MapControllers();
app.MapIdentityApi<User>();
app.Run();