0
0
RhSolutions-Api/RhSolutions.Api/Program.cs

41 lines
1.1 KiB
C#

using Microsoft.EntityFrameworkCore;
using RhSolutions.Models;
using RhSolutions.Api.Services;
using RhSolutions.Api.Middleware;
using RhSolutions.QueryModifiers;
var builder = WebApplication.CreateBuilder();
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>()
.AddScoped<IProductTypePredicter, ProductTypePredicter>()
.AddSingleton<ProductQueryModifierFactory>()
.AddGrpc();
builder.Services.AddControllers();
var app = builder.Build();
app.MapControllers();
app.MapGrpcService<SearchService>();
app.UseMiddleware<QueryModifier>();
app.Run();