refactor: Projektdateien migriert. Cloud-NuGet-Pakete durch lokale NuGet-Projekte ersetzt.
This commit is contained in:
49
StaffDBServer/_Shared/SharedExtensions/ServiceExtensions.cs
Normal file
49
StaffDBServer/_Shared/SharedExtensions/ServiceExtensions.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using HRD.AppLogger;
|
||||
using HRD.LDAPService.JWT;
|
||||
using HRD.WebApi.DAL.Middleware;
|
||||
using HRD.WebApi.Helpers;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Server.IISIntegration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace StaffDBServer.SharedExtensions
|
||||
{
|
||||
public static class ServiceExtensions
|
||||
{
|
||||
public static void ConfigureWebApiExtensionsAtFirst(this IServiceCollection services)
|
||||
{
|
||||
//services.AddCors();
|
||||
services.AddCustomCors("AllowAllOrigins");
|
||||
|
||||
services.Configure<IISOptions>(options =>
|
||||
{
|
||||
options.AuthenticationDisplayName = "Windows";
|
||||
options.ForwardClientCertificate = true;
|
||||
options.AutomaticAuthentication = true;
|
||||
});
|
||||
services.AddAuthentication(IISDefaults.AuthenticationScheme);
|
||||
|
||||
services.ConfigureJWT(Extends.JwtMiddlewareOptionsHelper.GetJwtMiddlewareOptions()); ;
|
||||
|
||||
services.ConfigureDAL(WebApiMiddlewareOptionsHelper.GetWebApiMiddlewareOptions());
|
||||
|
||||
services.AddSingleton<ILoggerManager, LoggerManager>();
|
||||
|
||||
services.ConfigureSwagger();
|
||||
}
|
||||
|
||||
public static void ConfigureWebApiExtensionsEnd(this IServiceCollection services)
|
||||
{
|
||||
services.AddMvc()
|
||||
.ConfigureApiBehaviorOptions(options =>
|
||||
{
|
||||
options.InvalidModelStateResponseFactory = context =>
|
||||
{
|
||||
var errors = new HRD.WebApi.Helpers.HttpErrorDetails(context);
|
||||
return new BadRequestObjectResult(errors);
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using NSwag;
|
||||
using NSwag.Generation.Processors.Security;
|
||||
using System.Linq;
|
||||
|
||||
namespace StaffDBServer.SharedExtensions
|
||||
{
|
||||
public static class ServiceSwaggerExtensions
|
||||
{
|
||||
public static void ConfigureSwagger(this IApplicationBuilder app)
|
||||
{
|
||||
app.UseSwaggerUi(cfg =>
|
||||
cfg.DocExpansion = "none" //"list"
|
||||
);
|
||||
}
|
||||
|
||||
public static void ConfigureSwagger(this IServiceCollection services)
|
||||
{
|
||||
services.AddSwaggerDocument(config =>
|
||||
{
|
||||
#region add Bearer Authorization
|
||||
|
||||
config.AddSecurity("JWT", Enumerable.Empty<string>(), new OpenApiSecurityScheme
|
||||
{
|
||||
Type = OpenApiSecuritySchemeType.ApiKey,
|
||||
Name = "Authorization",
|
||||
In = OpenApiSecurityApiKeyLocation.Header,
|
||||
Description = "Bearer JWT token."
|
||||
});
|
||||
|
||||
config.OperationProcessors.Add(
|
||||
new AspNetCoreOperationSecurityScopeProcessor("JWT"));
|
||||
|
||||
#endregion add Bearer Authorization
|
||||
|
||||
config.PostProcess = document =>
|
||||
{
|
||||
document.Info.Version = "V." + PlatformServices.Default.Application.ApplicationVersion + "; " + PlatformServices.Default.Application.RuntimeFramework;
|
||||
document.Info.Title = $" {PlatformServices.Default.Application.ApplicationName} API";
|
||||
document.Info.Description = $" {PlatformServices.Default.Application.ApplicationName} Backend ";
|
||||
document.Info.TermsOfService = "None";
|
||||
document.Info.Contact = new NSwag.OpenApiContact
|
||||
{
|
||||
Name = "IT",
|
||||
Email = string.Empty,
|
||||
Url = "https://hensel-recycling.com"
|
||||
};
|
||||
document.Info.License = new NSwag.OpenApiLicense
|
||||
{
|
||||
Name = "Commercial License",
|
||||
Url = "https://hensel-recycling.com"
|
||||
};
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using HRD.WebApi;
|
||||
using HRD.WebApi.DAL.Middleware;
|
||||
|
||||
namespace StaffDBServer.SharedExtensions
|
||||
{
|
||||
public static class WebApiMiddlewareOptionsHelper
|
||||
{
|
||||
public static WebApiMiddlewareOptions GetWebApiMiddlewareOptions()
|
||||
{
|
||||
WebApiMiddlewareOptions options = new WebApiMiddlewareOptions
|
||||
{
|
||||
AssemblyVersion = WebApiConfig.AssemblyVersion,
|
||||
AssemblyName = WebApiConfig.AssemblyName,
|
||||
ClientVersion = WebApiConfig.ClientVersion,
|
||||
|
||||
Connectionstring = WebApiConfig.Connectionstring,
|
||||
|
||||
NlogConnectionstring = WebApiConfig.NlogConnectionstring,
|
||||
NlogDBLogLevel = WebApiConfig.NlogDBLogLevel,
|
||||
NlogFileLogLevel = WebApiConfig.NlogFileLogLevel,
|
||||
NlogLogDirectory = WebApiConfig.NlogLogDirectory
|
||||
};
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user