JOBot/JOBot.Backend/Startup.cs
2025-07-25 16:37:42 +03:00

43 lines
1.4 KiB
C#

using JOBot.Backend.DAL.Context;
using JOBot.Backend.Infrastructure.Config;
using JOBot.Backend.Services;
using JOBot.Backend.Services.gRPC;
using Microsoft.EntityFrameworkCore;
using RabbitMQ.Client;
namespace JOBot.Backend;
public class Startup(IConfiguration configuration)
{
private IConfiguration Configuration { get; } = configuration;
public async Task ConfigureServices(IServiceCollection services)
{
services.AddGrpc();
services.AddGrpcReflection();
services.AddControllers();
services.AddLogging();
await using var rabbitMqConnection = await new ConnectionFactory
{
HostName = "jobot-rabbitmq"
}.CreateConnectionAsync();
await using var channel = await rabbitMqConnection.CreateChannelAsync();
await channel.QueueDeclareAsync(RabbitQueues.AuthQueue, false, false, false);
services.AddSingleton(channel);
services.AddDbContext<AppDbContext>(options =>
options.UseNpgsql(Configuration.GetConnectionString("PostgreSQL")));
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();
}
}