Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
45 lines (36 loc) · 1.54 KB
/
Copy pathProgram.cs
File metadata and controls
45 lines (36 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using Microsoft.EntityFrameworkCore;
using ReportingSystemService.Infrastructure;
using ReportingSystemService.Infrastructure.Messaging;
namespace ReportingSystemService
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<AddDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddSingleton<RabbitMqService>(); // Ðåãèñòðèðóåì RabbitMqService êàê ñèíãëòîí
builder.Services.AddSingleton<RabbitMqProducer>(); // Ðåãèñòðèðóåì RabbitMqProducer êàê ñèíãëòîí
builder.Services.AddHostedService<RabbitMqConsumer>(); // Ðåãèñòðèðóåì RabbitMqConsumer êàê ôîíîâóþ ñëóæáó
var app = builder.Build();
using (var scope = app.Services.CreateScope()) // Àâòî-ïðèìåíåíèå ìèãðàöèé ïðè çàïóñêå ïðèëîæåíèÿ
{
var db = scope.ServiceProvider.GetRequiredService<AddDbContext>();
db.Database.Migrate();
}
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
}
}
}