Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
76 lines (53 loc) · 2.12 KB
/
Copy pathProgram.cs
File metadata and controls
76 lines (53 loc) · 2.12 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using MongoDB.Driver;
using ProductService.AsyncDataServices;
using ProductService.Data;
using ProductService.Data.Caching;
using ProductService.EventProcessing;
using ProductService.Grpc;
using ProductService.Settings;
using StackExchange.Redis;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddScoped<IProductRepo, CachedProductRepo>();
builder.Services.AddScoped<ICacheRepo, CacheRepo>();
builder.Services.AddGrpc();
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
builder.Services.AddSingleton<IConnectionMultiplexer>(sp =>
{
var redisConfig = ConfigurationOptions.Parse(
builder.Configuration.GetConnectionString("Redis")!
);
redisConfig.AbortOnConnectFail = false;
redisConfig.ReconnectRetryPolicy = new ExponentialRetry(5000);
return ConnectionMultiplexer.Connect(redisConfig);
});
builder.Services.Configure<MongoSettings>(
builder.Configuration.GetSection("MongoSettings"));
var mongoSettings = builder.Configuration
.GetSection("MongoSettings")
.Get<MongoSettings>();
var client = new MongoClient(mongoSettings.ConnectionString);
var database = client.GetDatabase(mongoSettings.DatabaseName);
builder.Services.AddSingleton(database);
builder.Services.AddSingleton<IMessageBusClient, MessageBusClient>();
builder.Services.AddHostedService<MessageBusClientInitializer>();
builder.Services.AddSingleton<IEventProcessor, EventProcessor>();
builder.Services.AddHostedService<MessageBusSubscriber>();
builder.Services.AddOpenApi();
builder.Services.AddSingleton<ILogger>(provider =>
{
var logPath = Path.Combine("Logs", $"{DateTime.UtcNow:yyyy-MM-dd HH-mm-ss}.log");
return new Logger(logPath);
});
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.MapGrpcService<GrpcServer>();
//var products = await new TestingUtils().ParseProductsAsync(builder.Configuration, 4);
//new TestingUtils().Proccess(products, builder.Services.BuildServiceProvider().GetRequiredService<IProductRepo>());
app.Run();