JOBot/JOBot.Backend/Startup.cs

49 lines
1.5 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 async Task ConfigureServices(IServiceCollection services)
{
services.AddGrpc();
services.AddGrpcReflection();
services.AddControllers();
services.AddLogging();
await using var rabbitMqConnection = await new ConnectionFactory
{
HostName = "jobot-rabbitmq"
}.CreateConnectionAsync();
var channel = await rabbitMqConnection.CreateChannelAsync();
await channel.QueueDeclareAsync(
RabbitQueues.AuthQueue,
false,
false,
false,
arguments: null);
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();
}
}