-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathProgram.cs
More file actions
96 lines (80 loc) · 3.21 KB
/
Copy pathProgram.cs
File metadata and controls
96 lines (80 loc) · 3.21 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using Microsoft.GS.DPSHost.AppConfiguration;
using Microsoft.GS.DPSHost.ServiceConfiguration;
using Microsoft.GS.DPSHost.API;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using System.Reflection;
using Microsoft.GS.DPS.Storage.Document;
using NSwag.AspNetCore;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.ApplicationInsights.AspNetCore.Extensions;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
//Load Inject Settings and Load AppConfiguration Objects
AppConfiguration.Config(builder);
// Configure Application Insights - Always register to ensure TelemetryClient is available for DI
var connectionString = builder.Configuration["ApplicationInsights:ConnectionString"];
builder.Services.AddApplicationInsightsTelemetry(options =>
{
if (!string.IsNullOrEmpty(connectionString))
{
options.ConnectionString = connectionString;
options.EnableAdaptiveSampling = builder.Configuration.GetValue<bool>("ApplicationInsights:EnableAdaptiveSampling", true);
options.EnablePerformanceCounterCollectionModule = builder.Configuration.GetValue<bool>("ApplicationInsights:EnablePerformanceCounterCollectionModule", true);
options.EnableQuickPulseMetricStream = builder.Configuration.GetValue<bool>("ApplicationInsights:EnableQuickPulseMetricStream", true);
}
});
// Configure logging
if (!string.IsNullOrEmpty(connectionString))
{
builder.Logging.AddApplicationInsights();
}
builder.Logging.AddConsole();
builder.Logging.AddDebug();
//Bson Register Class Maps
//MongoDbConfig.RegisterClassMaps();
//Add Services (Dependency Injection)
ServiceDependencies.Inject(builder);
// Inject Kestrel server options
builder.Services.Configure<KestrelServerOptions>(options =>
{
//allow to upload files up to 500 MB
options.Limits.MaxRequestBodySize = 500 * 1024 * 1024; // 500 MB
options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(20);
options.Limits.RequestHeadersTimeout = TimeSpan.FromMinutes(20);
});
// Configure FormOptions to increase the maximum allowed size for multipart body length
builder.Services.Configure<FormOptions>(options =>
{
options.MultipartBodyLengthLimit = 500 * 1024 * 1024; // 500 MB
});
// Enable Corss-Origin Requests
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAll",
builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
});
var app = builder.Build();
// Add Minimum API Services
Operation.AddAPIs(app);
KernelMemory.AddAPIs(app);
Chat.AddAPIs(app);
UserInterface.AddAPIs(app);
// Inject the HTTP request pipeline.
// Swagger UI is enabled only in the Development environment to avoid exposing the
// API surface and schema in production (CodeQL SM04686). Set ASPNETCORE_ENVIRONMENT=Development
// (or use launchSettings.json) to access /swagger locally.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "API V1");
options.RoutePrefix = string.Empty;
});
}
app.UseCors("AllowAll");
app.UseHttpsRedirection();
app.Run();