You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.6 KiB
C#

using Expedience.Api.Consumers;
using Expedience.Api.Db;
using Expedience.Api.Encryption;
using MassTransit;
using Microsoft.EntityFrameworkCore;
using System.Reflection;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var connectionString = builder.Configuration.GetConnectionString("Expedience");
builder.Services.AddDbContext<ExpedienceContext>(options =>
options.UseNpgsql(connectionString));
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var rabbitMqHost = builder.Configuration.GetSection("RabbitMq")["Host"];
var userName = builder.Configuration.GetSection("RabbitMq")["UserName"];
var password = builder.Configuration.GetSection("RabbitMq")["Password"];
builder.Services.AddMassTransit(opt =>
{
opt.AddConsumersFromNamespaceContaining<DutyCompletionResultConsumer>();
opt.UsingRabbitMq((context, cfg) =>
{
cfg.Host(rabbitMqHost, h =>
{
h.Username(userName);
h.Password(password);
});
cfg.ConfigureEndpoints(context);
});
});
builder.Services.AddSingleton<IDecryptor, Decryptor>();
var app = builder.Build();
var scope = app.Services.CreateScope();
var dbContext = scope.ServiceProvider.GetRequiredService<ExpedienceContext>();
dbContext.Database.EnsureCreated();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();