-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
71 lines (61 loc) · 2.88 KB
/
Program.cs
File metadata and controls
71 lines (61 loc) · 2.88 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
using Microsoft.EntityFrameworkCore;
using StackExchange.Redis;
using BChatServer.Src.DB.Rdb;
using BChatServer.Src.Service;
using Serilog;
using System.Reflection;
namespace BChatServer{
/// <summary>
/// アプリケーションのエントリーポイント
/// </summary>
public static class Program{
/// <summary>
/// アプリケーションの実行メソッド
/// </summary>
/// <param name="args"></param>
/// <exception cref="ArgumentNullException"></exception>
public static void Main(string[] args){
var builder = WebApplication.CreateBuilder(args);
// ロガーの設定はアプリケーションの開始時に一度だけ行う
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateLogger();
// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
// XMLコメントファイルのパスを取得
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
options.IncludeXmlComments(xmlPath);
});
// Redisの接続設定
var redisConnectionString = builder.Configuration.GetSection("Redis")["ConnectionString"];
if(redisConnectionString is null){
throw new ArgumentNullException("Redis connection string is not set");
}else{
builder.Services.AddSingleton<RedisService>(new RedisService($"{redisConnectionString},abortConnect=false"));
}
//DbContextの接続設定
// PostgreSQLへの接続文字列を設定します
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
if(connectionString is null){
throw new ArgumentNullException("Connection string is not set");
}else{
builder.Services.AddDbContext<MyContext>(options => options.UseNpgsql(connectionString));
}
// TokenManageServiceの登録
builder.Services.AddTransient<TokenManageService>();
// Add controllers
builder.Services.AddControllers();
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
//コントローラークラスをマッピング
app.MapControllers();
app.UseHttpsRedirection();
app.Run();
}
}
}