-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathProgram.cs
65 lines (48 loc) · 1.68 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using Microsoft.EntityFrameworkCore;
using Project.API.Middlewares;
using Project.Infrastructure.Data;
using Project.API.Extensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using BenchmarkDotNet.Running;
using Project.API.Controllers;
using BenchmarkDotNet.Configs;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<ApplicationDbContext>(
options => options.UseSqlServer(builder.Configuration
.GetConnectionString("PrimaryDbConnection")));
// Register ILogger service
builder.Services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddSeq(builder.Configuration.GetSection("Seq"));
});
//Register Services
builder.Services.RegisterService();
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "Clean Structured API Project", Version = "v1" });
});
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseRouting(); // Add this line to configure routing
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers(); // Map your regular API controllers
// Add a custom endpoint for triggering benchmarks
endpoints.MapGet("/runbenchmarks", async context =>
{
// You can run the benchmarks here
var summary = BenchmarkRunner.Run<OrderControllerBenchmark>();
await context.Response.WriteAsync("Benchmarks completed. Check console for results.");
});
});
#region Custom Middleware
app.UseRequestResponseLogging();
#endregion
app.Run();