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

57 lines
1.5 KiB
C#
Raw Normal View History

2023-12-07 00:20:59 +00:00
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
2023-12-07 00:29:11 +00:00
using YPS.Beer.Configuration;
2023-12-07 00:20:59 +00:00
using YPS.Beer.Data;
using YPS.Beer.Models;
using YPS.Beer.Services;
var builder = WebApplication.CreateBuilder(args);
2023-12-07 00:29:11 +00:00
var punkServiceConfiguration = new PunkServiceConfiguration();
builder.Configuration.GetSection(PunkServiceConfiguration.ConfigurationSection).Bind(punkServiceConfiguration);
2023-12-07 00:20:59 +00:00
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddControllers();
2023-12-07 00:29:11 +00:00
builder.Services.AddHttpClient<IPunkService, PunkService>()
.ConfigureHttpClient(client => client.BaseAddress = new Uri(punkServiceConfiguration.BaseUrl));
2023-12-07 00:20:59 +00:00
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());
});
2023-12-07 00:20:59 +00:00
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseRouting();
2023-12-07 00:20:59 +00:00
app.UseHttpsRedirection();
app.UseCors();
app.UseAuthorization();
2023-12-07 00:20:59 +00:00
app.MapControllers();
app.MapIdentityApi<User>();
2023-12-07 00:29:11 +00:00
app.Run();