51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
using Microsoft.AspNetCore.Cors.Infrastructure;
|
|
using Microsoft.Extensions.Options;
|
|
using OFBButte.Application.Configuration;
|
|
using OFBButte.Application.Database;
|
|
using OFBButte.Application.Email;
|
|
using OFBButte.Database;
|
|
using OFBButte.Infrastructure.Email;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
string CorsPolicy = "OFBCorsPolicy";
|
|
|
|
builder.Services.AddCors(options =>
|
|
{
|
|
options.AddPolicy(CorsPolicy, policy =>
|
|
{
|
|
policy.WithOrigins("http://localhost:4200", "https://test.ofbbutte.com", "https://ofbbutte.com")
|
|
.AllowAnyHeader()
|
|
.AllowAnyMethod()
|
|
.AllowCredentials();
|
|
});
|
|
});
|
|
|
|
// App Settings
|
|
var appSettings = builder.Configuration.GetSection("App").Get<AppSettings>();
|
|
builder.Services.AddSingleton(appSettings);
|
|
|
|
// DB Context
|
|
builder.Services.AddDbContext<OFBContext>(o =>
|
|
{
|
|
OFBContext.UseMySql(o, builder.Configuration.GetConnectionString("OFBContext"));
|
|
});
|
|
builder.Services.AddScoped<IOFBContext, OFBContext>(s => s.GetService<OFBContext>());
|
|
|
|
// Email Service
|
|
builder.Services.AddScoped<IEmailSender, EmailSender>(s =>
|
|
{
|
|
var options = s.GetService<IOptions<AppSettings>>();
|
|
return new EmailSender(options.Value.Environment != "Prod");
|
|
});
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
app.MapGet("/", () => $"OFB API - {app.Environment.EnvironmentName}");
|
|
|
|
app.MapMissionaryRoutes();
|
|
|
|
|
|
app.Run();
|