-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathHostApplicationBuilderExtensions.cs
More file actions
39 lines (35 loc) · 1.66 KB
/
HostApplicationBuilderExtensions.cs
File metadata and controls
39 lines (35 loc) · 1.66 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
namespace ServiceControl.Audit.Infrastructure.WebApi
{
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using ModelContextProtocol.AspNetCore;
using ServiceControl.Infrastructure;
static class HostApplicationBuilderExtensions
{
public static void AddServiceControlAuditApi(this IHostApplicationBuilder builder, Settings.Settings settings)
{
if (settings.EnableMcpServer)
{
builder.Services
.AddMcpServer()
.WithHttpTransport()
.WithToolsFromAssembly();
}
builder.Services.AddCors(options => options.AddDefaultPolicy(Cors.GetDefaultPolicy(settings.CorsSettings)));
// We're not explicitly adding Gzip here because it's already in the default list of supported compressors
builder.Services.AddResponseCompression();
var controllers = builder.Services.AddControllers(options =>
{
options.Filters.Add<XParticularVersionHttpHandler>();
options.Filters.Add<CachingHttpHandler>();
options.Filters.Add<NotModifiedStatusHttpHandler>();
options.ModelBinderProviders.Insert(0, new PagingInfoModelBindingProvider());
options.ModelBinderProviders.Insert(0, new SortInfoModelBindingProvider());
});
controllers.AddApplicationPart(Assembly.GetExecutingAssembly());
controllers.AddJsonOptions(options => options.JsonSerializerOptions.CustomizeDefaults());
}
}
}