0
0
RhSolutions-Api/RhSolutions.Api/Program.cs
Sergey Chebotar da94ed6d89 Init commit
2022-12-14 09:53:10 +03:00

35 lines
1.0 KiB
C#

using Microsoft.EntityFrameworkCore;
using RhSolutions.Api.Models;
using RhSolutions.Api.Services;
var builder = WebApplication.CreateBuilder(args);
string dbHost = builder.Configuration["DB_HOST"],
dbPort = builder.Configuration["DB_PORT"],
dbName = builder.Configuration["DB_DATABASE"],
dbUser = builder.Configuration["DB_USER"],
dbPassword = builder.Configuration["DB_PASSWORD"];
string connectionString = builder.Configuration["ConnectionsStrings:RhSolutionsLocal"]
?? $"Host={dbHost};Port={dbPort};Database={dbName};Username={dbUser};Password={dbPassword}";
builder.Services.AddDbContext<RhSolutionsContext>(opts =>
{
opts.UseNpgsql(connectionString);
if (builder.Environment.IsDevelopment())
{
opts.EnableSensitiveDataLogging(true);
}
});
builder.Services.AddScoped<IPricelistParser, ClosedXMLParser>();
builder.Services.AddControllers();
var app = builder.Build();
app.MapControllers();
var context = app.Services.CreateScope().ServiceProvider
.GetRequiredService<RhSolutionsContext>();
app.Run();