-
Notifications
You must be signed in to change notification settings - Fork 2
/
Program.cs
42 lines (29 loc) · 1.15 KB
/
Program.cs
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
using System.Reflection;
using Mapster;
using MapsterMapper;
using StackExchange.Redis;
using Microsoft.EntityFrameworkCore;
using PostService.API.Models;
using PostService.API.Services;
using PostService.API.RedisCaching;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
// Register AppDbContext
var SQLConnectionString = builder.Configuration.GetConnectionString("DbConnection");
builder.Services.AddDbContextPool<AppDbContext>(op=>op.UseSqlServer(SQLConnectionString));
// Register PostServices
builder.Services.AddScoped<IPostServices, PostServices>();
// Register Mapster
var config = TypeAdapterConfig.GlobalSettings;
config.Scan(Assembly.GetExecutingAssembly());
builder.Services.AddSingleton(config);
builder.Services.AddScoped<IMapper, ServiceMapper>();
// Register Redis
builder.Services.AddSingleton<IConnectionMultiplexer>(opt=>ConnectionMultiplexer.Connect(builder.Configuration.GetConnectionString("RedisCacheURL")));
// Register Cache service
builder.Services.AddScoped<ICacheService, CacheService>();
var app = builder.Build();
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();