JOBot/JOBot.Backend/Startup.cs

53 lines
1.6 KiB
C#

using JOBot.Backend.DAL.Context;
using JOBot.Backend.Infrastructure.Config;
using JOBot.Backend.Services;
using JOBot.Backend.Services.gRPC;
using JOBot.Infrastructure.Config;
using Microsoft.EntityFrameworkCore;
using RabbitMQ.Client;
namespace JOBot.Backend;
public class Startup(IConfiguration configuration)
{
private IConfiguration Configuration { get; } = configuration;
public void ConfigureServices(IServiceCollection services)
{
services.AddGrpc();
services.AddGrpcReflection();
services.AddControllers();
services.AddLogging();
services.AddDbContext<AppDbContext>(options =>
options.UseNpgsql(Configuration.GetConnectionString("PostgreSQL")));
services.AddSingleton<IChannel>(x =>
{
var rabbitMqConnection = new ConnectionFactory
{
HostName = "rabbitmq"
}.CreateConnectionAsync().Result;
var channel = rabbitMqConnection.CreateChannelAsync().Result;
channel.QueueDeclareAsync(
RabbitQueues.AuthQueue,
false,
false,
false,
arguments: null).Wait();
return channel;
});
services.Configure<HeadHunterConfig>(Configuration.GetSection(HeadHunterConfig.SectionName));
services.AddScoped<HeadHunterService>();
}
public void Configure(WebApplication app, IWebHostEnvironment env)
{
app.MapGrpcReflectionService().AllowAnonymous();
app.MapGrpcService<UserService>();
app.MapControllers();
}
}