refactor: return the modified interfaces for further modification
This commit is contained in:
parent
4970dd782a
commit
428c2dc3ba
@ -5,9 +5,9 @@ namespace Mirea.Api.Endpoint.Configuration.Core.Startup;
|
|||||||
|
|
||||||
public static class ApiVersioningConfiguration
|
public static class ApiVersioningConfiguration
|
||||||
{
|
{
|
||||||
public static void AddCustomApiVersioning(this IServiceCollection services)
|
public static IApiVersioningBuilder AddCustomApiVersioning(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddApiVersioning(options =>
|
return services.AddApiVersioning(options =>
|
||||||
{
|
{
|
||||||
options.DefaultApiVersion = new ApiVersion(1, 0);
|
options.DefaultApiVersion = new ApiVersion(1, 0);
|
||||||
options.AssumeDefaultVersionWhenUnspecified = true;
|
options.AssumeDefaultVersionWhenUnspecified = true;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
@ -11,7 +12,7 @@ namespace Mirea.Api.Endpoint.Configuration.Core.Startup;
|
|||||||
|
|
||||||
public static class JwtConfiguration
|
public static class JwtConfiguration
|
||||||
{
|
{
|
||||||
public static IServiceCollection AddJwtToken(this IServiceCollection services, IConfiguration configuration)
|
public static AuthenticationBuilder AddJwtToken(this IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
var lifeTimeJwt = TimeSpan.FromMinutes(int.Parse(configuration["SECURITY_LIFE_TIME_JWT"]!));
|
var lifeTimeJwt = TimeSpan.FromMinutes(int.Parse(configuration["SECURITY_LIFE_TIME_JWT"]!));
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ public static class JwtConfiguration
|
|||||||
SigningKey = jwtKey
|
SigningKey = jwtKey
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddAuthentication(options =>
|
return services.AddAuthentication(options =>
|
||||||
{
|
{
|
||||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
@ -60,7 +61,5 @@ public static class JwtConfiguration
|
|||||||
TokenDecryptionKey = new SymmetricSecurityKey(jwtDecrypt)
|
TokenDecryptionKey = new SymmetricSecurityKey(jwtDecrypt)
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
return services;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ public static class LoggerConfiguration
|
|||||||
{
|
{
|
||||||
public static IHostBuilder AddCustomSerilog(this IHostBuilder hostBuilder)
|
public static IHostBuilder AddCustomSerilog(this IHostBuilder hostBuilder)
|
||||||
{
|
{
|
||||||
hostBuilder.UseSerilog((context, _, configuration) =>
|
return hostBuilder.UseSerilog((context, _, configuration) =>
|
||||||
{
|
{
|
||||||
var generalConfig = context.Configuration.Get<GeneralConfig>()?.LogSettings;
|
var generalConfig = context.Configuration.Get<GeneralConfig>()?.LogSettings;
|
||||||
configuration
|
configuration
|
||||||
@ -51,13 +51,11 @@ public static class LoggerConfiguration
|
|||||||
configuration.Filter.ByExcluding(Matching.WithProperty<string>("SourceContext", sc =>
|
configuration.Filter.ByExcluding(Matching.WithProperty<string>("SourceContext", sc =>
|
||||||
sc.Contains("Microsoft.EntityFrameworkCore.Database.Command")));
|
sc.Contains("Microsoft.EntityFrameworkCore.Database.Command")));
|
||||||
});
|
});
|
||||||
|
|
||||||
return hostBuilder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IApplicationBuilder UseCustomSerilog(this IApplicationBuilder app)
|
public static IApplicationBuilder UseCustomSerilog(this IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
app.UseSerilogRequestLogging(options =>
|
return app.UseSerilogRequestLogging(options =>
|
||||||
{
|
{
|
||||||
options.MessageTemplate = "[{RequestMethod}] {RequestPath} [Client {RemoteIPAddress}] [{StatusCode}] in {Elapsed:0.0000} ms";
|
options.MessageTemplate = "[{RequestMethod}] {RequestPath} [Client {RemoteIPAddress}] [{StatusCode}] in {Elapsed:0.0000} ms";
|
||||||
|
|
||||||
@ -75,7 +73,5 @@ public static class LoggerConfiguration
|
|||||||
diagnosticContext.Set("RemoteIPAddress", httpContext.Connection.RemoteIpAddress?.ToString());
|
diagnosticContext.Set("RemoteIPAddress", httpContext.Connection.RemoteIpAddress?.ToString());
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
return app;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,15 +51,13 @@ public static class SwaggerConfiguration
|
|||||||
options.IncludeXmlComments(Path.Combine(basePath, "ApiDtoDocs.xml"));
|
options.IncludeXmlComments(Path.Combine(basePath, "ApiDtoDocs.xml"));
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();
|
return services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();
|
||||||
|
|
||||||
return services;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IApplicationBuilder UseCustomSwagger(this IApplicationBuilder app, IServiceProvider services)
|
public static IApplicationBuilder UseCustomSwagger(this IApplicationBuilder app, IServiceProvider services)
|
||||||
{
|
{
|
||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI(options =>
|
return app.UseSwaggerUI(options =>
|
||||||
{
|
{
|
||||||
options.InjectStylesheet($"{UrlHelper.GetSubPath}css/swagger/SwaggerDark.css");
|
options.InjectStylesheet($"{UrlHelper.GetSubPath}css/swagger/SwaggerDark.css");
|
||||||
var provider = services.GetService<IApiVersionDescriptionProvider>();
|
var provider = services.GetService<IApiVersionDescriptionProvider>();
|
||||||
@ -72,7 +70,5 @@ public static class SwaggerConfiguration
|
|||||||
options.RoutePrefix = UrlHelper.GetSubPathSwagger.Trim('/');
|
options.RoutePrefix = UrlHelper.GetSubPathSwagger.Trim('/');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return app;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user