-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
132 lines (100 loc) · 4.11 KB
/
Program.cs
File metadata and controls
132 lines (100 loc) · 4.11 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
var builder = WebApplication.CreateBuilder(args);
var logger = new LoggerConfiguration()
.ReadFrom.Configuration(builder.Configuration)
.Enrich.FromLogContext()
.CreateLogger();
builder.Host.UseSerilog(logger);
//DATABASE CONNECTION
builder.Services.AddDbContext<MBDEVproAPIDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
// SERVICES
builder.Services.AddTransient<ICustomerService, CustomerService>();
// REPOSITORIES
builder.Services.AddTransient<ICustomerRepository, CustomerRepository>();
builder.Services.AddControllers();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
// Register the Swagger generator; custom details
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Version = "v1",
Title = "MBDEVproAPI v1 | .NET CORE 10",
Description = "manages business customers",
TermsOfService = new Uri("https://images3.alphacoders.com/967/thumb-1920-96797.jpg"),
Contact = new OpenApiContact
{
Name = "MBDEVproAPI Administrator",
Email = "[email protected]",
Url = new Uri("https://m.media-amazon.com/images/I/71rVfyrUzPL._SL1101_.jpg"),
},
License = new OpenApiLicense
{
Name = "No license",
Url = new Uri("https://example.com/license"),
}
});
});
//ADD: API security and authentication (OAuth2, OpenID Connect, JWT)
var app = builder.Build();
app.UseSerilogRequestLogging();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
//app.MapOpenApi(); // Expose the OpenAPI JSON endpoint
//app.MapScalarApiReference(); // Map the Scalar UI endpoint
Log.Information("MBDEVproAPI: (Development Environment)");
app.UseDeveloperExceptionPage();
}
if (app.Environment.EnvironmentName == "Test")
{
Log.Information("MBDEVproAPI: Test Environment)");
}
if (app.Environment.EnvironmentName == "Uat")
{
Log.Information("MBDEVproAPI: Uat Environment)");
}
if (app.Environment.EnvironmentName == "Production")
{
Log.Information("MBDEVproAPI: Production Environment)");
}
if (app.Environment.IsDevelopment() || app.Environment.EnvironmentName == "Test")
{
//app.UseSwagger();
//app.UseSwaggerUI(c =>
//{
// //c.SwaggerEndpoint("/MBDEVproAPI/swagger/v1/swagger.json", "MBDEVproAPI v1 .NET CORE 10");
// c.SwaggerEndpoint("../swagger/v1/swagger.json", "MBDEVproAPI v1 .NET CORE 10");
// // ENDPOINTS: https://localhost:7092/swagger/index.html
// // JSON: https://localhost:7092/swagger/v1/swagger.json
//});
}
//DEMO so can test with swagger and scalar UI, can remove later
app.MapOpenApi(); // Expose the OpenAPI JSON endpoint
app.MapScalarApiReference(); // Map the Scalar UI endpoint
Log.Information("MBDEVproAPI: (Development Environment)");
//app.UseDeveloperExceptionPage(); // For local only, can change later for testing and production environments, can also add custom error handling middleware for production environment.
app.MapScalarApiReference(options =>
{
options.Title = "MBDEVproAPI v1 .NET CORE 10";
options.WithTheme(ScalarTheme.Moon); // Use a specific theme
options.ForceDarkMode(); // Force dark mode
});
//DEMO so can test with swagger and scalar UI, can remove later
app.UseSwagger();
app.UseSwaggerUI(c =>
{
//c.SwaggerEndpoint("/MBDEVproAPI/swagger/v1/swagger.json", "MBDEVproAPI v1 .NET CORE 10");
c.SwaggerEndpoint("../swagger/v1/swagger.json", "MBDEVproAPI v1 .NET CORE 10");
// ENDPOINTS: https://localhost:7092/swagger/index.html
// JSON: https://localhost:7092/swagger/v1/swagger.json
});
app.UseSerilogRequestLogging(); // Add Serilog request logging middleware
app.UseDeveloperExceptionPage(); // For local only, can change later for testing and production environments, can also add custom error handling middleware for production environment.
//Middleware
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAuthorization();
app.MapControllers();
app.Run();