-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAspNetCoreExtensions.cs
36 lines (30 loc) · 1.32 KB
/
AspNetCoreExtensions.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
using Asp.Versioning;
using Asp.Versioning.ApiExplorer;
using Microsoft.Extensions.DependencyInjection;
using SmartIOT.Connector.Core;
using SmartIOT.Connector.RestApi.Services;
namespace SmartIOT.Connector.RestApi;
public static class AspNetCoreExtensions
{
public static IServiceCollection AddSmartIotConnectorRestApi(this IServiceCollection services, IConfigurationPersister configurationPersister)
{
services.AddControllers();
services.AddApiVersioning(config =>
{
config.DefaultApiVersion = new ApiVersion(1, 0);
config.AssumeDefaultVersionWhenUnspecified = true;
config.ReportApiVersions = true;
})
.AddApiExplorer(options =>
{
options.GroupNameFormat = "'v'VVV";
options.SubstituteApiVersionInUrl = true;
});
services.AddTransient<IApiVersionDescriptionProvider, GroupedApiVersionDescriptionProvider>();
services.ConfigureOptions<SwaggerVersioningOptions>();
services.AddTransient<IConnectorService, ConnectorService>();
services.AddTransient<IDeviceService, DeviceService>();
services.AddTransient<IConfigurationService>(s => new ConfigurationService(s.GetRequiredService<SmartIotConnector>(), configurationPersister));
return services;
}
}