-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathProgram.cs
44 lines (30 loc) · 1.53 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
43
44
using StackExchange.Redis;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
// this is necessary when you want Swagger read the XmlComments (of functions and parameters) to auto-generate Swagger UI help and descriptions. Very useful.
var xmlFilename = $"{System.Reflection.Assembly.GetExecutingAssembly().GetName().Name}.xml";
options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
});
//builder.Services.AddDistributedMemoryCache();
builder.Services.AddCors();
builder.Services.AddResponseCompression(opt => { opt.EnableForHttps = true; });
//builder.Services.AddHttpsRedirection(opt => { opt.HttpsPort = 443; });
////redis distributed cache service
var multiplexer = ConnectionMultiplexer.Connect(builder.Configuration.GetConnectionString("MyRedisConStr"));
builder.Services.AddSingleton<IConnectionMultiplexer>(multiplexer);
var app = builder.Build();
app.UseHttpsRedirection();
app.UseDefaultFiles(); //Must be called before app.UseStaticFiles()
app.UseStaticFiles();
app.UseResponseCompression();
app.UseSwagger();
app.UseSwaggerUI();
app.UseCors(options => { options.AllowAnyOrigin(); options.AllowAnyHeader(); options.AllowAnyMethod(); });
app.UseAuthorization();
app.MapControllers();
app.Run();