Use file scoped namepace
This commit is contained in:
@@ -2,28 +2,27 @@
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace GerstITS.Examples.Api.Configurations
|
||||
namespace GerstITS.Examples.Api.Configurations;
|
||||
|
||||
public static class IConfigurationExtensions
|
||||
{
|
||||
public static class IConfigurationExtensions
|
||||
#region Methods
|
||||
|
||||
public static TEnum GetFlaggedEnum<TEnum>(this IConfiguration configuration, string key)
|
||||
where TEnum : struct, IConvertible
|
||||
{
|
||||
#region Methods
|
||||
ThrowsAnExceptionIfTypeIsNotAnEnumeration<TEnum>();
|
||||
|
||||
public static TEnum GetFlaggedEnum<TEnum>(this IConfiguration configuration, string key)
|
||||
where TEnum : struct, IConvertible
|
||||
{
|
||||
ThrowsAnExceptionIfTypeIsNotAnEnumeration<TEnum>();
|
||||
|
||||
return (TEnum)(object)(configuration.GetSection(key)?
|
||||
.Get<TEnum[]>() ?? Enumerable.Empty<TEnum>())
|
||||
.Sum(i => (int)(object)i);
|
||||
}
|
||||
|
||||
private static void ThrowsAnExceptionIfTypeIsNotAnEnumeration<TEnum>() where TEnum : struct, IConvertible
|
||||
{
|
||||
if (!typeof(TEnum).IsEnum)
|
||||
throw new InvalidOperationException($"{typeof(TEnum)} is not supported.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
return (TEnum)(object)(configuration.GetSection(key)?
|
||||
.Get<TEnum[]>() ?? Enumerable.Empty<TEnum>())
|
||||
.Sum(i => (int)(object)i);
|
||||
}
|
||||
|
||||
private static void ThrowsAnExceptionIfTypeIsNotAnEnumeration<TEnum>() where TEnum : struct, IConvertible
|
||||
{
|
||||
if (!typeof(TEnum).IsEnum)
|
||||
throw new InvalidOperationException($"{typeof(TEnum)} is not supported.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -2,26 +2,25 @@
|
||||
using GerstITS.System.Configurations;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace GerstITS.Examples.Api.Configurations
|
||||
namespace GerstITS.Examples.Api.Configurations;
|
||||
|
||||
internal sealed class EntityFrameworkMigrationConfiguration : IEntityFrameworkMigrationConfiguration
|
||||
{
|
||||
internal sealed class EntityFrameworkMigrationConfiguration : IEntityFrameworkMigrationConfiguration
|
||||
#region Constructors
|
||||
|
||||
public EntityFrameworkMigrationConfiguration(string parentPrefix,
|
||||
Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
{
|
||||
#region Constructors
|
||||
var prefix = $"{parentPrefix}:{this.ToConfigurationPrefix()}";
|
||||
|
||||
public EntityFrameworkMigrationConfiguration(string parentPrefix,
|
||||
Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
{
|
||||
var prefix = $"{parentPrefix}:{this.ToConfigurationPrefix()}";
|
||||
|
||||
AutoMigrate = configuration.GetValue<bool>($"{prefix}:{nameof(AutoMigrate)}");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IMigrationConfiguration
|
||||
|
||||
public bool AutoMigrate { get; }
|
||||
|
||||
#endregion
|
||||
AutoMigrate = configuration.GetValue<bool>($"{prefix}:{nameof(AutoMigrate)}");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IMigrationConfiguration
|
||||
|
||||
public bool AutoMigrate { get; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -2,33 +2,32 @@
|
||||
using Microsoft.Net.Http.Headers;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace GerstITS.Examples.Api.Configurations
|
||||
namespace GerstITS.Examples.Api.Configurations;
|
||||
|
||||
internal sealed class OpenApiSecuritySchemeConfiguration : IOpenApiSecuritySchemeConfiguration
|
||||
{
|
||||
internal sealed class OpenApiSecuritySchemeConfiguration : IOpenApiSecuritySchemeConfiguration
|
||||
#region Properties
|
||||
|
||||
public bool AllowAnonymous { get; }
|
||||
public string HttpHeaderKey { get; }
|
||||
public string Scheme { get; }
|
||||
public SecuritySchemeType SchemeType { get; }
|
||||
public ParameterLocation ParameterLocation { get; }
|
||||
public string Description { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public OpenApiSecuritySchemeConfiguration()
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public bool AllowAnonymous { get; }
|
||||
public string HttpHeaderKey { get; }
|
||||
public string Scheme { get; }
|
||||
public SecuritySchemeType SchemeType { get; }
|
||||
public ParameterLocation ParameterLocation { get; }
|
||||
public string Description { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public OpenApiSecuritySchemeConfiguration()
|
||||
{
|
||||
AllowAnonymous = false;
|
||||
HttpHeaderKey = HeaderNames.Authorization;
|
||||
Scheme = "Bearer";
|
||||
SchemeType = SecuritySchemeType.Http;
|
||||
ParameterLocation = ParameterLocation.Header;
|
||||
Description = "Authorization header using the Bearer scheme (Value: Bearer {{access_token}}).";
|
||||
}
|
||||
|
||||
#endregion
|
||||
AllowAnonymous = false;
|
||||
HttpHeaderKey = HeaderNames.Authorization;
|
||||
Scheme = "Bearer";
|
||||
SchemeType = SecuritySchemeType.Http;
|
||||
ParameterLocation = ParameterLocation.Header;
|
||||
Description = "Authorization header using the Bearer scheme (Value: Bearer {{access_token}}).";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,34 +1,33 @@
|
||||
using GerstITS.Authentication.OpenId;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace GerstITS.Examples.Api.Configurations
|
||||
namespace GerstITS.Examples.Api.Configurations;
|
||||
|
||||
internal class OpenIdValidationConfiguration : IOpenIdValidationConfiguration
|
||||
{
|
||||
internal class OpenIdValidationConfiguration : IOpenIdValidationConfiguration
|
||||
#region Constructors
|
||||
|
||||
public OpenIdValidationConfiguration(string parentPrefix,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
#region Constructors
|
||||
var prefix = $"{parentPrefix}:Validate";
|
||||
|
||||
public OpenIdValidationConfiguration(string parentPrefix,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
var prefix = $"{parentPrefix}:Validate";
|
||||
|
||||
Issuer = configuration.GetValue<string>($"{prefix}:{nameof(Issuer)}");
|
||||
Audience = configuration.GetValue<string>($"{prefix}:{nameof(Audience)}");
|
||||
RsaPublicKey = configuration.GetValue<string>($"{prefix}:{nameof(RsaPublicKey)}");
|
||||
RequiredClaimType = configuration.GetValue<string>($"{prefix}:{nameof(RequiredClaimType)}");
|
||||
ValidateLifetime = configuration.GetValue<bool>($"{prefix}:{nameof(ValidateLifetime)}");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IOpenIdValidationConfiguration
|
||||
|
||||
public string Issuer { get; }
|
||||
public string Audience { get; }
|
||||
public string RsaPublicKey { get; }
|
||||
public string RequiredClaimType { get; }
|
||||
public bool ValidateLifetime { get; }
|
||||
|
||||
#endregion
|
||||
Issuer = configuration.GetValue<string>($"{prefix}:{nameof(Issuer)}");
|
||||
Audience = configuration.GetValue<string>($"{prefix}:{nameof(Audience)}");
|
||||
RsaPublicKey = configuration.GetValue<string>($"{prefix}:{nameof(RsaPublicKey)}");
|
||||
RequiredClaimType = configuration.GetValue<string>($"{prefix}:{nameof(RequiredClaimType)}");
|
||||
ValidateLifetime = configuration.GetValue<bool>($"{prefix}:{nameof(ValidateLifetime)}");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IOpenIdValidationConfiguration
|
||||
|
||||
public string Issuer { get; }
|
||||
public string Audience { get; }
|
||||
public string RsaPublicKey { get; }
|
||||
public string RequiredClaimType { get; }
|
||||
public bool ValidateLifetime { get; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -2,34 +2,33 @@
|
||||
using GerstITS.System.Configurations;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace GerstITS.Examples.Api.Configurations
|
||||
namespace GerstITS.Examples.Api.Configurations;
|
||||
|
||||
internal class OpenIdConfiguration : IOpenIdConfiguration
|
||||
{
|
||||
internal class OpenIdConfiguration : IOpenIdConfiguration
|
||||
#region Constructors
|
||||
|
||||
public OpenIdConfiguration(string parentPrefix,
|
||||
Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
{
|
||||
#region Constructors
|
||||
var prefix = $"{parentPrefix}:{this.ToConfigurationPrefix()}";
|
||||
|
||||
public OpenIdConfiguration(string parentPrefix,
|
||||
Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
{
|
||||
var prefix = $"{parentPrefix}:{this.ToConfigurationPrefix()}";
|
||||
Authority = configuration.GetValue<string>($"{prefix}:{nameof(Authority)}");
|
||||
RequireHttpsMetadata = configuration.GetValue<bool>($"{prefix}:{nameof(RequireHttpsMetadata)}");
|
||||
SaveToken = configuration.GetValue<bool>($"{prefix}:{nameof(SaveToken)}");
|
||||
|
||||
Authority = configuration.GetValue<string>($"{prefix}:{nameof(Authority)}");
|
||||
RequireHttpsMetadata = configuration.GetValue<bool>($"{prefix}:{nameof(RequireHttpsMetadata)}");
|
||||
SaveToken = configuration.GetValue<bool>($"{prefix}:{nameof(SaveToken)}");
|
||||
|
||||
Validate = new OpenIdValidationConfiguration(prefix, configuration);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IOpenIdConfiguration
|
||||
|
||||
public string Authority { get; }
|
||||
public bool RequireHttpsMetadata { get; }
|
||||
public bool SaveToken { get; }
|
||||
|
||||
public IOpenIdValidationConfiguration Validate { get; }
|
||||
|
||||
#endregion
|
||||
Validate = new OpenIdValidationConfiguration(prefix, configuration);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IOpenIdConfiguration
|
||||
|
||||
public string Authority { get; }
|
||||
public bool RequireHttpsMetadata { get; }
|
||||
public bool SaveToken { get; }
|
||||
|
||||
public IOpenIdValidationConfiguration Validate { get; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -2,31 +2,30 @@
|
||||
using GerstITS.Web.Api.Builder;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace GerstITS.Examples.Api.Configurations
|
||||
namespace GerstITS.Examples.Api.Configurations;
|
||||
|
||||
internal sealed class CorsPolicyConfiguration : ICorsPolicy, GerstITS.System.Configurations.IConfiguration
|
||||
{
|
||||
internal sealed class CorsPolicyConfiguration : ICorsPolicy, GerstITS.System.Configurations.IConfiguration
|
||||
#region Constructors
|
||||
|
||||
public CorsPolicyConfiguration(string parentPrefix, Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
{
|
||||
#region Constructors
|
||||
var prefix = $"{parentPrefix}:{this.ToConfigurationPrefix()}";
|
||||
|
||||
public CorsPolicyConfiguration(string parentPrefix, Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
{
|
||||
var prefix = $"{parentPrefix}:{this.ToConfigurationPrefix()}";
|
||||
|
||||
AllowCredentials = configuration.GetValue<bool>($"{prefix}:{nameof(AllowCredentials)}", false);
|
||||
AllowedOrigins = configuration.GetSection($"{prefix}:{nameof(AllowedOrigins)}").Get<string[]>() ?? new string[0];
|
||||
AllowedHeaders = configuration.GetSection($"{prefix}:{nameof(AllowedHeaders)}").Get<string[]>() ?? new string[0];
|
||||
AllowedMethods = configuration.GetSection($"{prefix}:{nameof(AllowedMethods)}").Get<string[]>() ?? new string[0];
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICorsPolicy
|
||||
|
||||
public bool AllowCredentials { get; }
|
||||
public string[] AllowedOrigins { get; set; }
|
||||
public string[] AllowedHeaders { get; set; }
|
||||
public string[] AllowedMethods { get; set; }
|
||||
|
||||
#endregion
|
||||
AllowCredentials = configuration.GetValue<bool>($"{prefix}:{nameof(AllowCredentials)}", false);
|
||||
AllowedOrigins = configuration.GetSection($"{prefix}:{nameof(AllowedOrigins)}").Get<string[]>() ?? new string[0];
|
||||
AllowedHeaders = configuration.GetSection($"{prefix}:{nameof(AllowedHeaders)}").Get<string[]>() ?? new string[0];
|
||||
AllowedMethods = configuration.GetSection($"{prefix}:{nameof(AllowedMethods)}").Get<string[]>() ?? new string[0];
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICorsPolicy
|
||||
|
||||
public bool AllowCredentials { get; }
|
||||
public string[] AllowedOrigins { get; set; }
|
||||
public string[] AllowedHeaders { get; set; }
|
||||
public string[] AllowedMethods { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -3,28 +3,27 @@ using GerstITS.Web.Api.Builder;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
|
||||
namespace GerstITS.Examples.Api.Configurations
|
||||
namespace GerstITS.Examples.Api.Configurations;
|
||||
|
||||
internal sealed class WebApiHeadersConfiguration : IHeaderConfiguration, IConfiguration
|
||||
{
|
||||
internal sealed class WebApiHeadersConfiguration : IHeaderConfiguration, IConfiguration
|
||||
#region Constructors
|
||||
|
||||
public WebApiHeadersConfiguration(string parentPrefix, Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
{
|
||||
#region Constructors
|
||||
var prefix = $"{parentPrefix}:{this.ToConfigurationPrefix()}";
|
||||
|
||||
public WebApiHeadersConfiguration(string parentPrefix, Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
ForwardedHeaders = new ForwardedHeadersOptions
|
||||
{
|
||||
var prefix = $"{parentPrefix}:{this.ToConfigurationPrefix()}";
|
||||
|
||||
ForwardedHeaders = new ForwardedHeadersOptions
|
||||
{
|
||||
ForwardedHeaders = configuration.GetFlaggedEnum<ForwardedHeaders>($"{prefix}:{nameof(ForwardedHeadersOptions)}:{nameof(ForwardedHeadersOptions.ForwardedHeaders)}")
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IHeaderConfiguration
|
||||
|
||||
public ForwardedHeadersOptions ForwardedHeaders { get; }
|
||||
|
||||
#endregion
|
||||
ForwardedHeaders = configuration.GetFlaggedEnum<ForwardedHeaders>($"{prefix}:{nameof(ForwardedHeadersOptions)}:{nameof(ForwardedHeadersOptions.ForwardedHeaders)}")
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IHeaderConfiguration
|
||||
|
||||
public ForwardedHeadersOptions ForwardedHeaders { get; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -2,34 +2,33 @@
|
||||
using GerstITS.Web.Api.Builder;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace GerstITS.Examples.Api.Configurations
|
||||
namespace GerstITS.Examples.Api.Configurations;
|
||||
|
||||
internal sealed class ServerConfiguration : IServerConfiguration
|
||||
{
|
||||
internal sealed class ServerConfiguration : IServerConfiguration
|
||||
#region Constructors
|
||||
|
||||
public ServerConfiguration(string parentPrefix, Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
{
|
||||
#region Constructors
|
||||
var prefix = $"{parentPrefix}:{this.ToConfigurationPrefix()}";
|
||||
|
||||
public ServerConfiguration(string parentPrefix, Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
{
|
||||
var prefix = $"{parentPrefix}:{this.ToConfigurationPrefix()}";
|
||||
UseHttpsRedirection = configuration.GetValue<bool>($"{prefix}:{nameof(UseHttpsRedirection)}");
|
||||
UseHsts = configuration.GetValue<bool>($"{prefix}:{nameof(UseHsts)}");
|
||||
UseCors = configuration.GetValue<bool>($"{prefix}:{nameof(UseCors)}");
|
||||
|
||||
UseHttpsRedirection = configuration.GetValue<bool>($"{prefix}:{nameof(UseHttpsRedirection)}");
|
||||
UseHsts = configuration.GetValue<bool>($"{prefix}:{nameof(UseHsts)}");
|
||||
UseCors = configuration.GetValue<bool>($"{prefix}:{nameof(UseCors)}");
|
||||
|
||||
Headers = new WebApiHeadersConfiguration(prefix, configuration);
|
||||
CorsPolicy = new CorsPolicyConfiguration(prefix, configuration);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IServerConfiguration
|
||||
|
||||
public bool UseHttpsRedirection { get; }
|
||||
public bool UseHsts { get; }
|
||||
public bool UseCors { get; }
|
||||
public IHeaderConfiguration Headers { get; }
|
||||
public ICorsPolicy CorsPolicy { get; }
|
||||
|
||||
#endregion
|
||||
Headers = new WebApiHeadersConfiguration(prefix, configuration);
|
||||
CorsPolicy = new CorsPolicyConfiguration(prefix, configuration);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IServerConfiguration
|
||||
|
||||
public bool UseHttpsRedirection { get; }
|
||||
public bool UseHsts { get; }
|
||||
public bool UseCors { get; }
|
||||
public IHeaderConfiguration Headers { get; }
|
||||
public ICorsPolicy CorsPolicy { get; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -3,27 +3,26 @@ using GerstITS.System.Configurations;
|
||||
using GerstITS.Web.Api.Swagger;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace GerstITS.Examples.Api.Configurations
|
||||
namespace GerstITS.Examples.Api.Configurations;
|
||||
|
||||
internal sealed class LicenseConfiguration : ILicense, System.Configurations.IConfiguration
|
||||
{
|
||||
internal sealed class LicenseConfiguration : ILicense, System.Configurations.IConfiguration
|
||||
#region Constructors
|
||||
|
||||
public LicenseConfiguration(string parentPrefix, Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
{
|
||||
#region Constructors
|
||||
var prefix = $"{parentPrefix}:{this.ToConfigurationPrefix()}";
|
||||
|
||||
public LicenseConfiguration(string parentPrefix, Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
{
|
||||
var prefix = $"{parentPrefix}:{this.ToConfigurationPrefix()}";
|
||||
|
||||
Name = configuration.GetValue<string>($"{prefix}:{nameof(Name)}");
|
||||
Url = configuration.GetValue<Uri>($"{prefix}:{nameof(Url)}");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ILicence
|
||||
|
||||
public string Name { get; }
|
||||
public Uri Url { get; }
|
||||
|
||||
#endregion
|
||||
Name = configuration.GetValue<string>($"{prefix}:{nameof(Name)}");
|
||||
Url = configuration.GetValue<Uri>($"{prefix}:{nameof(Url)}");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ILicence
|
||||
|
||||
public string Name { get; }
|
||||
public Uri Url { get; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -4,42 +4,41 @@ using GerstITS.System.Configurations;
|
||||
using GerstITS.Web.Api.Swagger;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace GerstITS.Examples.Api.Configurations
|
||||
namespace GerstITS.Examples.Api.Configurations;
|
||||
|
||||
internal sealed class SwaggerConfiguration : ISwaggerConfiguration
|
||||
{
|
||||
internal sealed class SwaggerConfiguration : ISwaggerConfiguration
|
||||
#region Constructors
|
||||
|
||||
public SwaggerConfiguration(string parentPrefix,
|
||||
Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
{
|
||||
#region Constructors
|
||||
var prefix = $"{parentPrefix}:{this.ToConfigurationPrefix()}";
|
||||
|
||||
public SwaggerConfiguration(string parentPrefix,
|
||||
Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
{
|
||||
var prefix = $"{parentPrefix}:{this.ToConfigurationPrefix()}";
|
||||
var currentAssembly = typeof(WebApiConfiguration).Assembly;
|
||||
var fileVersionInfo = FileVersionInfo.GetVersionInfo(currentAssembly.Location);
|
||||
|
||||
var currentAssembly = typeof(WebApiConfiguration).Assembly;
|
||||
var fileVersionInfo = FileVersionInfo.GetVersionInfo(currentAssembly.Location);
|
||||
Name = fileVersionInfo.ProductName;
|
||||
Company = fileVersionInfo.CompanyName;
|
||||
SupportEMail = configuration.GetValue<string>($"{prefix}:{nameof(SupportEMail)}");
|
||||
TermsOfService = configuration.GetValue<Uri>($"{prefix}:{nameof(TermsOfService)}");
|
||||
|
||||
Name = fileVersionInfo.ProductName;
|
||||
Company = fileVersionInfo.CompanyName;
|
||||
SupportEMail = configuration.GetValue<string>($"{prefix}:{nameof(SupportEMail)}");
|
||||
TermsOfService = configuration.GetValue<Uri>($"{prefix}:{nameof(TermsOfService)}");
|
||||
|
||||
Release = currentAssembly.GetName().Version;
|
||||
License = new LicenseConfiguration(prefix, configuration);
|
||||
Security = new OpenApiSecuritySchemeConfiguration();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ISwaggerConfiguration
|
||||
|
||||
public string Name { get; }
|
||||
public string Company { get; }
|
||||
public string SupportEMail { get; }
|
||||
public Uri TermsOfService { get; }
|
||||
public Version Release { get; }
|
||||
public ILicense License { get; }
|
||||
public IOpenApiSecuritySchemeConfiguration Security { get; }
|
||||
|
||||
#endregion
|
||||
Release = currentAssembly.GetName().Version;
|
||||
License = new LicenseConfiguration(prefix, configuration);
|
||||
Security = new OpenApiSecuritySchemeConfiguration();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ISwaggerConfiguration
|
||||
|
||||
public string Name { get; }
|
||||
public string Company { get; }
|
||||
public string SupportEMail { get; }
|
||||
public Uri TermsOfService { get; }
|
||||
public Version Release { get; }
|
||||
public ILicense License { get; }
|
||||
public IOpenApiSecuritySchemeConfiguration Security { get; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -4,31 +4,30 @@ using GerstITS.System.Configurations;
|
||||
using GerstITS.Web.Api.Builder;
|
||||
using GerstITS.Web.Api.Swagger;
|
||||
|
||||
namespace GerstITS.Examples.Api.Configurations
|
||||
namespace GerstITS.Examples.Api.Configurations;
|
||||
|
||||
internal sealed class WebApiConfiguration : IConfiguration
|
||||
{
|
||||
internal sealed class WebApiConfiguration : IConfiguration
|
||||
#region Properties
|
||||
|
||||
public IServerConfiguration Server { get; }
|
||||
public IOpenIdConfiguration OpenId { get; }
|
||||
public ISwaggerConfiguration Swagger { get; set; }
|
||||
public IEntityFrameworkMigrationConfiguration EntityFrameworkMigration { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public WebApiConfiguration(Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
{
|
||||
#region Properties
|
||||
var prefix = this.ToConfigurationPrefix();
|
||||
|
||||
public IServerConfiguration Server { get; }
|
||||
public IOpenIdConfiguration OpenId { get; }
|
||||
public ISwaggerConfiguration Swagger { get; set; }
|
||||
public IEntityFrameworkMigrationConfiguration EntityFrameworkMigration { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public WebApiConfiguration(Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
{
|
||||
var prefix = this.ToConfigurationPrefix();
|
||||
|
||||
EntityFrameworkMigration = new EntityFrameworkMigrationConfiguration(prefix, configuration);
|
||||
OpenId = new OpenIdConfiguration(prefix, configuration);
|
||||
Server = new ServerConfiguration(prefix, configuration);
|
||||
Swagger = new SwaggerConfiguration(prefix, configuration);
|
||||
}
|
||||
|
||||
#endregion
|
||||
EntityFrameworkMigration = new EntityFrameworkMigrationConfiguration(prefix, configuration);
|
||||
OpenId = new OpenIdConfiguration(prefix, configuration);
|
||||
Server = new ServerConfiguration(prefix, configuration);
|
||||
Swagger = new SwaggerConfiguration(prefix, configuration);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -2,18 +2,17 @@
|
||||
using GerstITS.Data;
|
||||
using GerstITS.Web.Api.ExceptionHandling;
|
||||
|
||||
namespace GerstITS.Examples.Api.ExceptionHandling
|
||||
namespace GerstITS.Examples.Api.ExceptionHandling;
|
||||
|
||||
public class EntityNotFoundExceptionTransformation : ExceptionTransformationBase<EntityNotFoundException>
|
||||
{
|
||||
public class EntityNotFoundExceptionTransformation : ExceptionTransformationBase<EntityNotFoundException>
|
||||
protected override ExceptionTransformationInfo CreateExceptionTransformationInfo(EntityNotFoundException exception, string ticketId)
|
||||
{
|
||||
protected override ExceptionTransformationInfo CreateExceptionTransformationInfo(EntityNotFoundException exception, string ticketId)
|
||||
return new ExceptionTransformationInfo
|
||||
{
|
||||
return new ExceptionTransformationInfo
|
||||
{
|
||||
StatusCode = HttpStatusCode.NotFound,
|
||||
ReasonPhrase = "Enitity nicht gefunden",
|
||||
Details = exception.Message
|
||||
};
|
||||
}
|
||||
StatusCode = HttpStatusCode.NotFound,
|
||||
ReasonPhrase = "Enitity nicht gefunden",
|
||||
Details = exception.Message
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -2,22 +2,21 @@
|
||||
using System.Net;
|
||||
using GerstITS.Web.Api.ExceptionHandling;
|
||||
|
||||
namespace GerstITS.Examples.Api.ExceptionHandling
|
||||
namespace GerstITS.Examples.Api.ExceptionHandling;
|
||||
|
||||
internal sealed class ValidationExceptionTransformation : ExceptionTransformationBase<ValidationException>
|
||||
{
|
||||
internal sealed class ValidationExceptionTransformation : ExceptionTransformationBase<ValidationException>
|
||||
#region Methods
|
||||
|
||||
protected override ExceptionTransformationInfo CreateExceptionTransformationInfo(ValidationException exception, string ticketId)
|
||||
{
|
||||
#region Methods
|
||||
|
||||
protected override ExceptionTransformationInfo CreateExceptionTransformationInfo(ValidationException exception, string ticketId)
|
||||
return new ExceptionTransformationInfo
|
||||
{
|
||||
return new ExceptionTransformationInfo
|
||||
{
|
||||
StatusCode = HttpStatusCode.BadRequest,
|
||||
ReasonPhrase = "Validierungsfehler",
|
||||
Details = exception.Message
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
StatusCode = HttpStatusCode.BadRequest,
|
||||
ReasonPhrase = "Validierungsfehler",
|
||||
Details = exception.Message
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -3,37 +3,36 @@ using GerstITS.Examples.Logic.Example;
|
||||
using GerstITS.IoC;
|
||||
using GerstITS.System.Json;
|
||||
|
||||
namespace GerstITS.Examples.Api.StartupTasks
|
||||
namespace GerstITS.Examples.Api.StartupTasks;
|
||||
|
||||
internal class ExampleStartupTask : IStartupTask
|
||||
{
|
||||
internal class ExampleStartupTask : IStartupTask
|
||||
#region Fields#
|
||||
|
||||
private readonly IExampleProvider _provider;
|
||||
private readonly IJsonConvert _jsonConvert;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Construtcors
|
||||
|
||||
public ExampleStartupTask(IExampleProvider provider,
|
||||
IJsonConvert jsonConvert)
|
||||
{
|
||||
#region Fields#
|
||||
|
||||
private readonly IExampleProvider _provider;
|
||||
private readonly IJsonConvert _jsonConvert;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Construtcors
|
||||
|
||||
public ExampleStartupTask(IExampleProvider provider,
|
||||
IJsonConvert jsonConvert)
|
||||
{
|
||||
_jsonConvert = jsonConvert;
|
||||
_provider = provider;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStartupTask
|
||||
|
||||
public StartupPriorities Priority => StartupPriorities.Normal;
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
Debug.WriteLine($"---> {nameof(ExampleStartupTask)}: {_jsonConvert.Serialize(_provider.GetById(123))}");
|
||||
}
|
||||
|
||||
#endregion
|
||||
_jsonConvert = jsonConvert;
|
||||
_provider = provider;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStartupTask
|
||||
|
||||
public StartupPriorities Priority => StartupPriorities.Normal;
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
Debug.WriteLine($"---> {nameof(ExampleStartupTask)}: {_jsonConvert.Serialize(_provider.GetById(123))}");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
namespace GerstITS.Examples.Api.Versioning
|
||||
namespace GerstITS.Examples.Api.Versioning;
|
||||
|
||||
public static class Versions
|
||||
{
|
||||
public static class Versions
|
||||
{
|
||||
#region Versions
|
||||
#region Versions
|
||||
|
||||
public const string _1_0 = "1.0";
|
||||
public const string _1_1 = "1.1";
|
||||
public const string _1_0 = "1.0";
|
||||
public const string _1_1 = "1.1";
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -5,48 +5,47 @@ using GerstITS.Web.Api;
|
||||
using GerstITS.Web.Api.FluentApi;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace GerstITS.Examples.Api.Controllers
|
||||
namespace GerstITS.Examples.Api.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Controller is deprecated use newer version.
|
||||
/// </summary>
|
||||
[ApiController,
|
||||
ApiVersion(Versions._1_0, Deprecated = true),
|
||||
Route(ApplicationEnvironment.WebApi.ControllerRouteTemplate)]
|
||||
public class ExampleController : FluentApiControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Controller is deprecated use newer version.
|
||||
/// </summary>
|
||||
[ApiController,
|
||||
ApiVersion(Versions._1_0, Deprecated = true),
|
||||
Route(ApplicationEnvironment.WebApi.ControllerRouteTemplate)]
|
||||
public class ExampleController : FluentApiControllerBase
|
||||
#region Fields
|
||||
|
||||
private readonly IExampleProvider _provider;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public ExampleController(IExampleProvider provider,
|
||||
IValidator validator)
|
||||
: base(validator)
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private readonly IExampleProvider _provider;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public ExampleController(IExampleProvider provider,
|
||||
IValidator validator)
|
||||
: base(validator)
|
||||
{
|
||||
_provider = provider;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets the example data by id.
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns>Returns Example data.</returns>
|
||||
[HttpGet,
|
||||
Route("{id}")]
|
||||
public IActionResult Get(int id)
|
||||
{
|
||||
return Api().Use(id)
|
||||
.Get(_provider.GetById);
|
||||
}
|
||||
|
||||
#endregion
|
||||
_provider = provider;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets the example data by id.
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns>Returns Example data.</returns>
|
||||
[HttpGet,
|
||||
Route("{id}")]
|
||||
public IActionResult Get(int id)
|
||||
{
|
||||
return Api().Use(id)
|
||||
.Get(_provider.GetById);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -5,48 +5,47 @@ using GerstITS.Web.Api;
|
||||
using GerstITS.Web.Api.FluentApi;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace GerstITS.Examples.Api.Controllers._1._1
|
||||
namespace GerstITS.Examples.Api.Controllers._1._1;
|
||||
|
||||
/// <summary>
|
||||
/// Is responsible to get employee organization assignment examples.
|
||||
/// </summary>
|
||||
[ApiController,
|
||||
ApiVersion(Versions._1_1),
|
||||
Route(ApplicationEnvironment.WebApi.ControllerRouteTemplate)]
|
||||
public class ExampleController : FluentApiControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Is responsible to get employee organization assignment examples.
|
||||
/// </summary>
|
||||
[ApiController,
|
||||
ApiVersion(Versions._1_1),
|
||||
Route(ApplicationEnvironment.WebApi.ControllerRouteTemplate)]
|
||||
public class ExampleController : FluentApiControllerBase
|
||||
#region Fields
|
||||
|
||||
private readonly IExampleProvider _provider;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public ExampleController(IExampleProvider provider,
|
||||
IValidator validator)
|
||||
: base(validator)
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private readonly IExampleProvider _provider;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public ExampleController(IExampleProvider provider,
|
||||
IValidator validator)
|
||||
: base(validator)
|
||||
{
|
||||
_provider = provider;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets a employee organization assignment by specified id.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the employee organization assignment.</param>
|
||||
/// <returns>Returns an employee organization assignment</returns>
|
||||
[HttpGet,
|
||||
Route("{id}")]
|
||||
public IActionResult Get(int id)
|
||||
{
|
||||
return Api().Use(id)
|
||||
.Get(_provider.GetById_v1_1);
|
||||
}
|
||||
|
||||
#endregion
|
||||
_provider = provider;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets a employee organization assignment by specified id.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the employee organization assignment.</param>
|
||||
/// <returns>Returns an employee organization assignment</returns>
|
||||
[HttpGet,
|
||||
Route("{id}")]
|
||||
public IActionResult Get(int id)
|
||||
{
|
||||
return Api().Use(id)
|
||||
.Get(_provider.GetById_v1_1);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,22 +1,21 @@
|
||||
using GerstITS.Examples.Api.Configurations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace GerstITS.Examples.Api
|
||||
namespace GerstITS.Examples.Api;
|
||||
|
||||
public sealed partial class Module
|
||||
{
|
||||
public sealed partial class Module
|
||||
#region Methods
|
||||
|
||||
private static void RegisterConfigurations(IServiceCollection container)
|
||||
{
|
||||
#region Methods
|
||||
container.AddSingleton<WebApiConfiguration>();
|
||||
|
||||
private static void RegisterConfigurations(IServiceCollection container)
|
||||
{
|
||||
container.AddSingleton<WebApiConfiguration>();
|
||||
|
||||
container.AddSingleton(c => c.GetService<WebApiConfiguration>().EntityFrameworkMigration);
|
||||
container.AddSingleton(c => c.GetService<WebApiConfiguration>().OpenId);
|
||||
container.AddSingleton(c => c.GetService<WebApiConfiguration>().Server);
|
||||
container.AddSingleton(c => c.GetService<WebApiConfiguration>().Swagger);
|
||||
}
|
||||
|
||||
#endregion
|
||||
container.AddSingleton(c => c.GetService<WebApiConfiguration>().EntityFrameworkMigration);
|
||||
container.AddSingleton(c => c.GetService<WebApiConfiguration>().OpenId);
|
||||
container.AddSingleton(c => c.GetService<WebApiConfiguration>().Server);
|
||||
container.AddSingleton(c => c.GetService<WebApiConfiguration>().Swagger);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -2,17 +2,16 @@
|
||||
using GerstITS.Web.Api.ExceptionHandling.Extensions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace GerstITS.Examples.Api
|
||||
namespace GerstITS.Examples.Api;
|
||||
|
||||
public sealed partial class Module
|
||||
{
|
||||
public sealed partial class Module
|
||||
#region Methods
|
||||
|
||||
private static void RegisterExceptionHandling(IServiceCollection container)
|
||||
{
|
||||
#region Methods
|
||||
|
||||
private static void RegisterExceptionHandling(IServiceCollection container)
|
||||
{
|
||||
container.RegisterExceptionTransformationsOf<ValidationExceptionTransformation>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
container.RegisterExceptionTransformationsOf<ValidationExceptionTransformation>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,21 +1,20 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace GerstITS.Examples.Api
|
||||
namespace GerstITS.Examples.Api;
|
||||
|
||||
public sealed partial class Module
|
||||
{
|
||||
public sealed partial class Module
|
||||
#region Methods
|
||||
|
||||
private static void RegisterMvc(IServiceCollection container)
|
||||
{
|
||||
#region Methods
|
||||
//container.AddTransient<IConfigureOptions<MvcOptions>, ApiMvcOptions>();
|
||||
//container.AddTransient<IConfigureOptions<MvcNewtonsoftJsonOptions>, MvcJsonOptions>();
|
||||
|
||||
private static void RegisterMvc(IServiceCollection container)
|
||||
{
|
||||
//container.AddTransient<IConfigureOptions<MvcOptions>, ApiMvcOptions>();
|
||||
//container.AddTransient<IConfigureOptions<MvcNewtonsoftJsonOptions>, MvcJsonOptions>();
|
||||
|
||||
container.AddMvc()
|
||||
.AddNewtonsoftJson();
|
||||
}
|
||||
|
||||
#endregion
|
||||
container.AddMvc()
|
||||
.AddNewtonsoftJson();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -2,17 +2,16 @@
|
||||
using GerstITS.IoC.DotNetCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace GerstITS.Examples.Api
|
||||
namespace GerstITS.Examples.Api;
|
||||
|
||||
public sealed partial class Module
|
||||
{
|
||||
public sealed partial class Module
|
||||
#region Methods
|
||||
|
||||
private static void RegisterStartupTasks(IServiceCollection container)
|
||||
{
|
||||
#region Methods
|
||||
|
||||
private static void RegisterStartupTasks(IServiceCollection container)
|
||||
{
|
||||
container.RegisterStartupTasksOf<ExampleStartupTask>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
container.RegisterStartupTasksOf<ExampleStartupTask>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,20 +1,19 @@
|
||||
using GerstITS.IoC;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace GerstITS.Examples.Api
|
||||
namespace GerstITS.Examples.Api;
|
||||
|
||||
public sealed partial class Module : IIoCModule<IServiceCollection>
|
||||
{
|
||||
public sealed partial class Module : IIoCModule<IServiceCollection>
|
||||
#region IIoCModule
|
||||
|
||||
public void RegisterComponents(IServiceCollection container)
|
||||
{
|
||||
#region IIoCModule
|
||||
|
||||
public void RegisterComponents(IServiceCollection container)
|
||||
{
|
||||
RegisterConfigurations(container);
|
||||
RegisterExceptionHandling(container);
|
||||
RegisterMvc(container);
|
||||
RegisterStartupTasks(container);
|
||||
}
|
||||
|
||||
#endregion
|
||||
RegisterConfigurations(container);
|
||||
RegisterExceptionHandling(container);
|
||||
RegisterMvc(container);
|
||||
RegisterStartupTasks(container);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,23 +1,22 @@
|
||||
using GerstITS.Logging.Serilog;
|
||||
using GerstITS.Web.Api.Hosting;
|
||||
|
||||
namespace GerstITS.Examples.Api
|
||||
namespace GerstITS.Examples.Api;
|
||||
|
||||
public class Program : ProgramBase<Program>
|
||||
{
|
||||
public class Program : ProgramBase<Program>
|
||||
#region Methods
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
#region Methods
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
BootstrapLogContext.Execute<Program>(_ => Run(args));
|
||||
}
|
||||
|
||||
protected override void ConfigureWebHost(IWebHostBuilder webHostBuilder)
|
||||
{
|
||||
webHostBuilder.UseLogging()
|
||||
.UseStartup<Startup>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
BootstrapLogContext.Execute<Program>(_ => Run(args));
|
||||
}
|
||||
|
||||
protected override void ConfigureWebHost(IWebHostBuilder webHostBuilder)
|
||||
{
|
||||
webHostBuilder.UseLogging()
|
||||
.UseStartup<Startup>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -4,31 +4,30 @@ using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace GerstITS.Examples.Api
|
||||
namespace GerstITS.Examples.Api;
|
||||
|
||||
public class Startup : BootstrapperStartupBase
|
||||
{
|
||||
public class Startup : BootstrapperStartupBase
|
||||
#region Methods
|
||||
|
||||
protected override void ConfigureApplication(IApplicationBuilder applicationBuilder, IWebHostEnvironment webHostEnvironment)
|
||||
{
|
||||
#region Methods
|
||||
if (webHostEnvironment.IsProduction())
|
||||
applicationBuilder.UsePreconfiguredHsts();
|
||||
else
|
||||
applicationBuilder.UseDeveloperExceptionPage()
|
||||
.UseSwagger();
|
||||
|
||||
protected override void ConfigureApplication(IApplicationBuilder applicationBuilder, IWebHostEnvironment webHostEnvironment)
|
||||
{
|
||||
if (webHostEnvironment.IsProduction())
|
||||
applicationBuilder.UsePreconfiguredHsts();
|
||||
else
|
||||
applicationBuilder.UseDeveloperExceptionPage()
|
||||
.UseSwagger();
|
||||
|
||||
applicationBuilder.UsePreconfiguredCors()
|
||||
.UsePreconfiguredForwardedHeaders()
|
||||
.UsePreconfiguredHttpsRedirection()
|
||||
.UseAuthentication()
|
||||
.UseAuthorization()
|
||||
.UseRouting()
|
||||
.UseEndpoints(endpoints => endpoints.MapControllers())
|
||||
.UseRewriteUnknownPathsToIndexSite(ApplicationEnvironment.WebApi.BaseUrl)
|
||||
.UseSystemIndependentStaticFiles();
|
||||
}
|
||||
|
||||
#endregion
|
||||
applicationBuilder.UsePreconfiguredCors()
|
||||
.UsePreconfiguredForwardedHeaders()
|
||||
.UsePreconfiguredHttpsRedirection()
|
||||
.UseAuthentication()
|
||||
.UseAuthorization()
|
||||
.UseRouting()
|
||||
.UseEndpoints(endpoints => endpoints.MapControllers())
|
||||
.UseRewriteUnknownPathsToIndexSite(ApplicationEnvironment.WebApi.BaseUrl)
|
||||
.UseSystemIndependentStaticFiles();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
using GerstITS.Job.Scheduling;
|
||||
|
||||
namespace GerstITS.Examples.Jobs.SayHelloWorld.Configurations
|
||||
namespace GerstITS.Examples.Jobs.SayHelloWorld.Configurations;
|
||||
|
||||
public class SayHelloWorldJobConfiguration : JobSchedulingConfigurationBase
|
||||
{
|
||||
public class SayHelloWorldJobConfiguration : JobSchedulingConfigurationBase
|
||||
#region Constructors
|
||||
|
||||
public SayHelloWorldJobConfiguration(Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
: base(configuration)
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
public SayHelloWorldJobConfiguration(Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
: base(configuration)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -6,40 +6,39 @@ using GerstITS.Job;
|
||||
using GerstITS.System.Environment;
|
||||
using Quartz;
|
||||
|
||||
namespace GerstITS.Examples.Jobs.SayHelloWorld.Jobs
|
||||
namespace GerstITS.Examples.Jobs.SayHelloWorld.Jobs;
|
||||
|
||||
[DisallowConcurrentExecution]
|
||||
public class SayHelloWorldJob : JobBase
|
||||
{
|
||||
[DisallowConcurrentExecution]
|
||||
public class SayHelloWorldJob : JobBase
|
||||
#region Fields
|
||||
|
||||
private readonly SayHelloWorldJobConfiguration _configuration;
|
||||
private readonly Stopwatch _stopWatch;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cosntructors
|
||||
|
||||
public SayHelloWorldJob(SayHelloWorldJobConfiguration configuration,
|
||||
ISystemClock systemClock)
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private readonly SayHelloWorldJobConfiguration _configuration;
|
||||
private readonly Stopwatch _stopWatch;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cosntructors
|
||||
|
||||
public SayHelloWorldJob(SayHelloWorldJobConfiguration configuration,
|
||||
ISystemClock systemClock)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_stopWatch = new Stopwatch();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
protected override void Execute()
|
||||
{
|
||||
_stopWatch.Restart();
|
||||
Thread.Sleep(4000);
|
||||
|
||||
_stopWatch.Stop();
|
||||
Debug.WriteLine($"---> Say hello to world from {_configuration.Name}, Duration: {_stopWatch.ElapsedMilliseconds / 1000}s");
|
||||
}
|
||||
|
||||
#endregion
|
||||
_configuration = configuration;
|
||||
_stopWatch = new Stopwatch();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
protected override void Execute()
|
||||
{
|
||||
_stopWatch.Restart();
|
||||
Thread.Sleep(4000);
|
||||
|
||||
_stopWatch.Stop();
|
||||
Debug.WriteLine($"---> Say hello to world from {_configuration.Name}, Duration: {_stopWatch.ElapsedMilliseconds / 1000}s");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -4,17 +4,16 @@ using GerstITS.IoC;
|
||||
using GerstITS.Job.Scheduling;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace GerstITS.Examples.Jobs.SayHelloWorld
|
||||
namespace GerstITS.Examples.Jobs.SayHelloWorld;
|
||||
|
||||
public sealed class Module : IIoCModule<IServiceCollection>
|
||||
{
|
||||
public sealed class Module : IIoCModule<IServiceCollection>
|
||||
#region IIoCModule
|
||||
|
||||
public void RegisterComponents(IServiceCollection container)
|
||||
{
|
||||
#region IIoCModule
|
||||
|
||||
public void RegisterComponents(IServiceCollection container)
|
||||
{
|
||||
container.RegisterJob<SayHelloWorldJob, SayHelloWorldJobConfiguration>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
container.RegisterJob<SayHelloWorldJob, SayHelloWorldJobConfiguration>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
namespace GerstITS.Examples.Logic.Example
|
||||
namespace GerstITS.Examples.Logic.Example;
|
||||
|
||||
public class Example
|
||||
{
|
||||
public class Example
|
||||
{
|
||||
#region Properties
|
||||
#region Properties
|
||||
|
||||
public string FirstName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string FirstName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public string Description { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
namespace GerstITS.Examples.Logic.Example
|
||||
namespace GerstITS.Examples.Logic.Example;
|
||||
|
||||
public interface IExampleProvider
|
||||
{
|
||||
public interface IExampleProvider
|
||||
{
|
||||
Example GetById(int id);
|
||||
Example GetById_v1_1(int id);
|
||||
}
|
||||
Example GetById(int id);
|
||||
Example GetById_v1_1(int id);
|
||||
}
|
||||
@@ -1,51 +1,50 @@
|
||||
using AutoMapper;
|
||||
using GerstITS.Data;
|
||||
|
||||
namespace GerstITS.Examples.Logic.Example
|
||||
namespace GerstITS.Examples.Logic.Example;
|
||||
|
||||
internal sealed class ExampleProvider : IExampleProvider
|
||||
{
|
||||
internal sealed class ExampleProvider : IExampleProvider
|
||||
#region Fields
|
||||
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public ExampleProvider(IMapper mapper)
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public ExampleProvider(IMapper mapper)
|
||||
{
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IExampleProvider
|
||||
|
||||
public Example GetById(int id)
|
||||
{
|
||||
ThrowsAnExceptionIfEntityIsNotFound(id);
|
||||
|
||||
return _mapper.Map<Example>(id);
|
||||
}
|
||||
|
||||
public Example GetById_v1_1(int id)
|
||||
{
|
||||
ThrowsAnExceptionIfEntityIsNotFound(id);
|
||||
|
||||
return _mapper.Map<Example>(id);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private static void ThrowsAnExceptionIfEntityIsNotFound(int id)
|
||||
{
|
||||
if (id % 2 == 0)
|
||||
throw new EntityNotFoundException($"Example mit der Id '{id}' nicht gefunden.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IExampleProvider
|
||||
|
||||
public Example GetById(int id)
|
||||
{
|
||||
ThrowsAnExceptionIfEntityIsNotFound(id);
|
||||
|
||||
return _mapper.Map<Example>(id);
|
||||
}
|
||||
|
||||
public Example GetById_v1_1(int id)
|
||||
{
|
||||
ThrowsAnExceptionIfEntityIsNotFound(id);
|
||||
|
||||
return _mapper.Map<Example>(id);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private static void ThrowsAnExceptionIfEntityIsNotFound(int id)
|
||||
{
|
||||
if (id % 2 == 0)
|
||||
throw new EntityNotFoundException($"Example mit der Id '{id}' nicht gefunden.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,19 +1,18 @@
|
||||
using AutoMapper;
|
||||
|
||||
namespace GerstITS.Examples.Logic.Example
|
||||
namespace GerstITS.Examples.Logic.Example;
|
||||
|
||||
internal sealed class IntegerMapping : Profile
|
||||
{
|
||||
internal sealed class IntegerMapping : Profile
|
||||
#region Construtcors
|
||||
|
||||
public IntegerMapping()
|
||||
{
|
||||
#region Construtcors
|
||||
|
||||
public IntegerMapping()
|
||||
{
|
||||
CreateMap<int, Example>()
|
||||
.ForMember(x => x.FirstName, m => m.MapFrom((s, _) => $"First Name {s}"))
|
||||
.ForMember(x => x.LastName, m => m.MapFrom((s, _) => $"Last Name {s}"))
|
||||
.ForMember(x => x.Description, m => m.MapFrom((s, _) => $"Useful description for id '{s}'"));
|
||||
}
|
||||
|
||||
#endregion
|
||||
CreateMap<int, Example>()
|
||||
.ForMember(x => x.FirstName, m => m.MapFrom((s, _) => $"First Name {s}"))
|
||||
.ForMember(x => x.LastName, m => m.MapFrom((s, _) => $"Last Name {s}"))
|
||||
.ForMember(x => x.Description, m => m.MapFrom((s, _) => $"Useful description for id '{s}'"));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -2,19 +2,18 @@
|
||||
using GerstITS.Mapping.AutoMapper;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace GerstITS.Examples.Logic
|
||||
namespace GerstITS.Examples.Logic;
|
||||
|
||||
public sealed partial class Module
|
||||
{
|
||||
public sealed partial class Module
|
||||
#region Methods
|
||||
|
||||
private static void RegisterExample(IServiceCollection container)
|
||||
{
|
||||
#region Methods
|
||||
container.RegisterMappingsOf<IExampleProvider>();
|
||||
|
||||
private static void RegisterExample(IServiceCollection container)
|
||||
{
|
||||
container.RegisterMappingsOf<IExampleProvider>();
|
||||
|
||||
container.AddScoped<IExampleProvider, ExampleProvider>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
container.AddScoped<IExampleProvider, ExampleProvider>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -4,19 +4,18 @@ using GerstITS.Search;
|
||||
using GerstITS.Validation;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace GerstITS.Examples.Logic
|
||||
namespace GerstITS.Examples.Logic;
|
||||
|
||||
public sealed partial class Module
|
||||
{
|
||||
public sealed partial class Module
|
||||
#region Methods
|
||||
|
||||
private static void RegisterShared(IServiceCollection container)
|
||||
{
|
||||
#region Methods
|
||||
container.RegisterValidationRulesOf<IdValidationRule>();
|
||||
|
||||
private static void RegisterShared(IServiceCollection container)
|
||||
{
|
||||
container.RegisterValidationRulesOf<IdValidationRule>();
|
||||
|
||||
container.AddScoped<ISortingProvider, SortingProvider>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
container.AddScoped<ISortingProvider, SortingProvider>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,18 +1,17 @@
|
||||
using GerstITS.IoC;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace GerstITS.Examples.Logic
|
||||
namespace GerstITS.Examples.Logic;
|
||||
|
||||
public sealed partial class Module : IIoCModule<IServiceCollection>
|
||||
{
|
||||
public sealed partial class Module : IIoCModule<IServiceCollection>
|
||||
#region IIoCModule
|
||||
|
||||
public void RegisterComponents(IServiceCollection container)
|
||||
{
|
||||
#region IIoCModule
|
||||
|
||||
public void RegisterComponents(IServiceCollection container)
|
||||
{
|
||||
RegisterExample(container);
|
||||
RegisterShared(container);
|
||||
}
|
||||
|
||||
#endregion
|
||||
RegisterExample(container);
|
||||
RegisterShared(container);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -4,28 +4,27 @@ using System.Linq.Expressions;
|
||||
using GerstITS.Common;
|
||||
using GerstITS.Data;
|
||||
|
||||
namespace GerstITS.Examples.Logic.Shared
|
||||
namespace GerstITS.Examples.Logic.Shared;
|
||||
|
||||
internal static class ISearchEngineExtensions
|
||||
{
|
||||
internal static class ISearchEngineExtensions
|
||||
#region Methods
|
||||
|
||||
public static TEntity QueryBy<TEntity>(this IReadOnlyRepository repository, Expression<Func<TEntity, bool>> condition)
|
||||
where TEntity : IEntity
|
||||
{
|
||||
#region Methods
|
||||
|
||||
public static TEntity QueryBy<TEntity>(this IReadOnlyRepository repository, Expression<Func<TEntity, bool>> condition)
|
||||
where TEntity : IEntity
|
||||
{
|
||||
return repository.Query<TEntity>()
|
||||
.Where(condition)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public static TModel ThrowsAnExceptionIfNotFound<TModel, TKey>(this TModel model, TKey id)
|
||||
{
|
||||
if (model.IsNull())
|
||||
throw new EntityNotFoundException($"{typeof(TModel).Name} with id '{id}' not found.");
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
#endregion
|
||||
return repository.Query<TEntity>()
|
||||
.Where(condition)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public static TModel ThrowsAnExceptionIfNotFound<TModel, TKey>(this TModel model, TKey id)
|
||||
{
|
||||
if (model.IsNull())
|
||||
throw new EntityNotFoundException($"{typeof(TModel).Name} with id '{id}' not found.");
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
namespace GerstITS.Examples.Logic.Shared.Search.Sorting
|
||||
namespace GerstITS.Examples.Logic.Shared.Search.Sorting;
|
||||
|
||||
internal interface ISortable
|
||||
{
|
||||
internal interface ISortable
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -5,46 +5,45 @@ using System.Reflection;
|
||||
using GerstITS.Common;
|
||||
using GerstITS.Search;
|
||||
|
||||
namespace GerstITS.Examples.Logic.Shared.Search.Sorting
|
||||
namespace GerstITS.Examples.Logic.Shared.Search.Sorting;
|
||||
|
||||
internal class SortingProvider : ISortingProvider
|
||||
{
|
||||
internal class SortingProvider : ISortingProvider
|
||||
#region ISortingProvider
|
||||
|
||||
public bool CanSort<TItem>(IQueryable<TItem> query)
|
||||
{
|
||||
#region ISortingProvider
|
||||
|
||||
public bool CanSort<TItem>(IQueryable<TItem> query)
|
||||
{
|
||||
return typeof(TItem).IsAssignableTo(typeof(ISortable));
|
||||
}
|
||||
|
||||
public IQueryable<TItem> Sort<TItem>(IQueryable<TItem> query, ISorting sorting)
|
||||
{
|
||||
var propertyInfo = typeof(TItem).GetProperties()
|
||||
.SingleOrDefault(i => string.Equals(i.Name, sorting.SortBy, StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
if (!CanSort(query) || propertyInfo.IsNull())
|
||||
return query;
|
||||
|
||||
var sortExpression = CreateSortExpression<TItem>(propertyInfo);
|
||||
|
||||
return (sorting.SortDirection == SortingDirections.Ascending
|
||||
? query.OrderBy(sortExpression)
|
||||
: query.OrderByDescending(sortExpression))
|
||||
.AsQueryable();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private static Expression<Func<TItem, object>> CreateSortExpression<TItem>(MemberInfo propertyInfo)
|
||||
{
|
||||
var parameterExpression = Expression.Parameter(typeof(TItem), "x");
|
||||
var propertyExpression = Expression.Property(parameterExpression, propertyInfo.Name);
|
||||
var convertExpression = Expression.Convert(propertyExpression, typeof(object));
|
||||
|
||||
return Expression.Lambda<Func<TItem, object>>(convertExpression, parameterExpression);
|
||||
}
|
||||
|
||||
#endregion
|
||||
return typeof(TItem).IsAssignableTo(typeof(ISortable));
|
||||
}
|
||||
|
||||
public IQueryable<TItem> Sort<TItem>(IQueryable<TItem> query, ISorting sorting)
|
||||
{
|
||||
var propertyInfo = typeof(TItem).GetProperties()
|
||||
.SingleOrDefault(i => string.Equals(i.Name, sorting.SortBy, StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
if (!CanSort(query) || propertyInfo.IsNull())
|
||||
return query;
|
||||
|
||||
var sortExpression = CreateSortExpression<TItem>(propertyInfo);
|
||||
|
||||
return (sorting.SortDirection == SortingDirections.Ascending
|
||||
? query.OrderBy(sortExpression)
|
||||
: query.OrderByDescending(sortExpression))
|
||||
.AsQueryable();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private static Expression<Func<TItem, object>> CreateSortExpression<TItem>(MemberInfo propertyInfo)
|
||||
{
|
||||
var parameterExpression = Expression.Parameter(typeof(TItem), "x");
|
||||
var propertyExpression = Expression.Property(parameterExpression, propertyInfo.Name);
|
||||
var convertExpression = Expression.Convert(propertyExpression, typeof(object));
|
||||
|
||||
return Expression.Lambda<Func<TItem, object>>(convertExpression, parameterExpression);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,19 +1,18 @@
|
||||
using FluentValidation;
|
||||
using GerstITS.Validation;
|
||||
|
||||
namespace GerstITS.Examples.Logic.Shared.Validation
|
||||
namespace GerstITS.Examples.Logic.Shared.Validation;
|
||||
|
||||
internal sealed class IdValidationRule : ValidationRuleBase<int>
|
||||
{
|
||||
internal sealed class IdValidationRule : ValidationRuleBase<int>
|
||||
#region Constructors
|
||||
|
||||
public IdValidationRule()
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
public IdValidationRule()
|
||||
{
|
||||
RuleFor(x => x)
|
||||
.GreaterThan(0)
|
||||
.OverridePropertyName("id");
|
||||
}
|
||||
|
||||
#endregion
|
||||
RuleFor(x => x)
|
||||
.GreaterThan(0)
|
||||
.OverridePropertyName("id");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -5,21 +5,20 @@ using GerstITS.IoC.DotNetCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace GerstITS.Examples.WebClient.Console
|
||||
namespace GerstITS.Examples.WebClient.Console;
|
||||
|
||||
public class Module : IIoCModule<IServiceCollection>
|
||||
{
|
||||
public class Module : IIoCModule<IServiceCollection>
|
||||
#region IIoCModule
|
||||
|
||||
public void RegisterComponents(IServiceCollection container)
|
||||
{
|
||||
#region IIoCModule
|
||||
container.AddTransient<IApplicationStart, TestRunner>();
|
||||
|
||||
public void RegisterComponents(IServiceCollection container)
|
||||
{
|
||||
container.AddTransient<IApplicationStart, TestRunner>();
|
||||
|
||||
container.AddTransient<IConfiguration>(c => new ConfigurationBuilder().SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
|
||||
.AddJsonFile("appsettings.json", false, true)
|
||||
.Build());
|
||||
}
|
||||
|
||||
#endregion
|
||||
container.AddTransient<IConfiguration>(c => new ConfigurationBuilder().SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
|
||||
.AddJsonFile("appsettings.json", false, true)
|
||||
.Build());
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,31 +1,30 @@
|
||||
using GerstITS.IoC.DotNetCore;
|
||||
|
||||
namespace GerstITS.Examples.WebClient.Console
|
||||
namespace GerstITS.Examples.WebClient.Console;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
internal class Program
|
||||
#region Fields
|
||||
|
||||
private static readonly DotNetCoreApplicationBootstrapper _bootstrapper;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
static Program()
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private static readonly DotNetCoreApplicationBootstrapper _bootstrapper;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
static Program()
|
||||
{
|
||||
_bootstrapper = new DotNetCoreApplicationBootstrapper();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
_bootstrapper.Run();
|
||||
}
|
||||
|
||||
#endregion
|
||||
_bootstrapper = new DotNetCoreApplicationBootstrapper();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
_bootstrapper.Run();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -4,48 +4,47 @@ using GerstITS.Examples.WebClients.Examples.Api;
|
||||
using GerstITS.IoC.DotNetCore;
|
||||
using GerstITS.Web.WebClients;
|
||||
|
||||
namespace GerstITS.Examples.WebClient.Console.Tests
|
||||
namespace GerstITS.Examples.WebClient.Console.Tests;
|
||||
|
||||
internal sealed class TestRunner : IApplicationStart
|
||||
{
|
||||
internal sealed class TestRunner : IApplicationStart
|
||||
#region Fields
|
||||
|
||||
private readonly IWebClient _webClient;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Construtors
|
||||
|
||||
public TestRunner(IWebClient webClient)
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private readonly IWebClient _webClient;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Construtors
|
||||
|
||||
public TestRunner(IWebClient webClient)
|
||||
{
|
||||
_webClient = webClient;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ITestRunner
|
||||
|
||||
public void Run()
|
||||
{
|
||||
var result1 = _webClient.Request<ICountry>()
|
||||
.Execute(c => c.Search(new SearchCriteria
|
||||
{ SortBy = nameof(Country.Name), SortDirection = SortingDirections.Descending, Skip = 5, Take = 5}));
|
||||
|
||||
var result2 = _webClient.Request<ICountry>()
|
||||
.Execute(c => c.Get(result1.Value.Result.First().Id));
|
||||
|
||||
var test3 = _webClient.Request<ICountry>()
|
||||
.Execute(c => c.Create(new Country {Name = $"Country-{Guid.NewGuid()}"}));
|
||||
|
||||
test3.Value.Name += "_Renamed";
|
||||
|
||||
var test4 = _webClient.Request<ICountry>()
|
||||
.Execute(c => c.Update(test3.Value));
|
||||
|
||||
var test5 = _webClient.Request<ICountry>()
|
||||
.Execute(c => c.Delete(test3.Value.Id));
|
||||
}
|
||||
|
||||
#endregion
|
||||
_webClient = webClient;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ITestRunner
|
||||
|
||||
public void Run()
|
||||
{
|
||||
var result1 = _webClient.Request<ICountry>()
|
||||
.Execute(c => c.Search(new SearchCriteria
|
||||
{ SortBy = nameof(Country.Name), SortDirection = SortingDirections.Descending, Skip = 5, Take = 5}));
|
||||
|
||||
var result2 = _webClient.Request<ICountry>()
|
||||
.Execute(c => c.Get(result1.Value.Result.First().Id));
|
||||
|
||||
var test3 = _webClient.Request<ICountry>()
|
||||
.Execute(c => c.Create(new Country {Name = $"Country-{Guid.NewGuid()}"}));
|
||||
|
||||
test3.Value.Name += "_Renamed";
|
||||
|
||||
var test4 = _webClient.Request<ICountry>()
|
||||
.Execute(c => c.Update(test3.Value));
|
||||
|
||||
var test5 = _webClient.Request<ICountry>()
|
||||
.Execute(c => c.Delete(test3.Value.Id));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
using GerstITS.Web.Rest.WebClients;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace GerstITS.Examples.WebClients.Examples.Api.Configurations
|
||||
namespace GerstITS.Examples.WebClients.Examples.Api.Configurations;
|
||||
|
||||
internal class ExampleApiClientConfiguration : RestWebServiceConfigurationBase
|
||||
{
|
||||
internal class ExampleApiClientConfiguration : RestWebServiceConfigurationBase
|
||||
#region Constructors
|
||||
|
||||
public ExampleApiClientConfiguration(IConfiguration configuration)
|
||||
: base(configuration)
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
public ExampleApiClientConfiguration(IConfiguration configuration)
|
||||
: base(configuration)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,27 +1,26 @@
|
||||
using GerstITS.Web.WebClients;
|
||||
|
||||
namespace GerstITS.Examples.WebClients.Examples.Api
|
||||
namespace GerstITS.Examples.WebClients.Examples.Api;
|
||||
|
||||
public interface ICountry : IWebService
|
||||
{
|
||||
public interface ICountry : IWebService
|
||||
{
|
||||
[WebMethod(WebMethods.Get),
|
||||
ResourceUrl("Country/{id}")]
|
||||
Country Get(int id);
|
||||
[WebMethod(WebMethods.Get),
|
||||
ResourceUrl("Country/{id}")]
|
||||
Country Get(int id);
|
||||
|
||||
[WebMethod(WebMethods.Get),
|
||||
ResourceUrl("Country/Search")]
|
||||
SearchResult<Country> Search(SearchCriteria criteria);
|
||||
[WebMethod(WebMethods.Get),
|
||||
ResourceUrl("Country/Search")]
|
||||
SearchResult<Country> Search(SearchCriteria criteria);
|
||||
|
||||
[WebMethod(WebMethods.Post),
|
||||
ResourceUrl("Country")]
|
||||
Country Create(Country model);
|
||||
[WebMethod(WebMethods.Post),
|
||||
ResourceUrl("Country")]
|
||||
Country Create(Country model);
|
||||
|
||||
[WebMethod(WebMethods.Put),
|
||||
ResourceUrl("Country")]
|
||||
void Update(Country model);
|
||||
[WebMethod(WebMethods.Put),
|
||||
ResourceUrl("Country")]
|
||||
void Update(Country model);
|
||||
|
||||
[WebMethod(WebMethods.Delete),
|
||||
ResourceUrl("Country/{id}")]
|
||||
void Delete(int id);
|
||||
}
|
||||
[WebMethod(WebMethods.Delete),
|
||||
ResourceUrl("Country/{id}")]
|
||||
void Delete(int id);
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
namespace GerstITS.Examples.WebClients.Examples.Api
|
||||
namespace GerstITS.Examples.WebClients.Examples.Api;
|
||||
|
||||
public class Country
|
||||
{
|
||||
public class Country
|
||||
{
|
||||
#region Properties
|
||||
#region Properties
|
||||
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -1,18 +1,17 @@
|
||||
namespace GerstITS.Examples.WebClients.Examples.Api
|
||||
namespace GerstITS.Examples.WebClients.Examples.Api;
|
||||
|
||||
public class SearchCriteria
|
||||
{
|
||||
public class SearchCriteria
|
||||
{
|
||||
#region Properties
|
||||
#region Properties
|
||||
|
||||
internal int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
internal int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public int? Skip { get; set; }
|
||||
public int? Take { get; set; }
|
||||
public int? Skip { get; set; }
|
||||
public int? Take { get; set; }
|
||||
|
||||
public string SortBy { get; set; }
|
||||
public SortingDirections SortDirection { get; set; }
|
||||
public string SortBy { get; set; }
|
||||
public SortingDirections SortDirection { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -1,24 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GerstITS.Examples.WebClients.Examples.Api
|
||||
namespace GerstITS.Examples.WebClients.Examples.Api;
|
||||
|
||||
public class SearchResult<TItem>
|
||||
{
|
||||
public class SearchResult<TItem>
|
||||
#region Properties
|
||||
|
||||
public int TotalCount { get; set; }
|
||||
public IEnumerable<TItem> Result { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public SearchResult()
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public int TotalCount { get; set; }
|
||||
public IEnumerable<TItem> Result { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public SearchResult()
|
||||
{
|
||||
Result = Array.Empty<TItem>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
Result = Array.Empty<TItem>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
namespace GerstITS.Examples.WebClients.Examples.Api
|
||||
namespace GerstITS.Examples.WebClients.Examples.Api;
|
||||
|
||||
public enum SortingDirections
|
||||
{
|
||||
public enum SortingDirections
|
||||
{
|
||||
Ascending = 0,
|
||||
Descending
|
||||
}
|
||||
Ascending = 0,
|
||||
Descending
|
||||
}
|
||||
@@ -2,24 +2,23 @@
|
||||
using GerstITS.Examples.WebClients.Examples.Api.Configurations;
|
||||
using GerstITS.Web.Rest.WebClients;
|
||||
|
||||
namespace GerstITS.Examples.WebClients.Examples.Api.CreationRules
|
||||
namespace GerstITS.Examples.WebClients.Examples.Api.CreationRules;
|
||||
|
||||
internal sealed class ExampleApiClientCreatingRule : RestApiClientCreationRuleBase<ExampleApiClientConfiguration>
|
||||
{
|
||||
internal sealed class ExampleApiClientCreatingRule : RestApiClientCreationRuleBase<ExampleApiClientConfiguration>
|
||||
#region Properties
|
||||
|
||||
protected override Type[] SupportedTypes => new[] { typeof(ICountry) };
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public ExampleApiClientCreatingRule(ExampleApiClientConfiguration configuration,
|
||||
Func<IRestWebServiceConfiguration, IRestWebServiceClient> restWebServiceClientFactory)
|
||||
: base(configuration, restWebServiceClientFactory)
|
||||
{
|
||||
#region Properties
|
||||
|
||||
protected override Type[] SupportedTypes => new[] { typeof(ICountry) };
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public ExampleApiClientCreatingRule(ExampleApiClientConfiguration configuration,
|
||||
Func<IRestWebServiceConfiguration, IRestWebServiceClient> restWebServiceClientFactory)
|
||||
: base(configuration, restWebServiceClientFactory)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
using GerstITS.Examples.WebClients.Examples.Api.Configurations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace GerstITS.Examples.WebClients.Examples.Api
|
||||
namespace GerstITS.Examples.WebClients.Examples.Api;
|
||||
|
||||
public sealed partial class Module
|
||||
{
|
||||
public sealed partial class Module
|
||||
#region Methods
|
||||
|
||||
private static void RegisterConfigurations(IServiceCollection container)
|
||||
{
|
||||
#region Methods
|
||||
|
||||
private static void RegisterConfigurations(IServiceCollection container)
|
||||
{
|
||||
container.AddSingleton<ExampleApiClientConfiguration>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
container.AddSingleton<ExampleApiClientConfiguration>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -2,17 +2,16 @@
|
||||
using GerstITS.Web.WebClients;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace GerstITS.Examples.WebClients.Examples.Api
|
||||
namespace GerstITS.Examples.WebClients.Examples.Api;
|
||||
|
||||
public sealed partial class Module
|
||||
{
|
||||
public sealed partial class Module
|
||||
#region Methods
|
||||
|
||||
private static void RegisterCreationRules(IServiceCollection container)
|
||||
{
|
||||
#region Methods
|
||||
|
||||
private static void RegisterCreationRules(IServiceCollection container)
|
||||
{
|
||||
container.AddTransient<IWebServiceClientCreationRule, ExampleApiClientCreatingRule>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
container.AddTransient<IWebServiceClientCreationRule, ExampleApiClientCreatingRule>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,18 +1,17 @@
|
||||
using GerstITS.IoC;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace GerstITS.Examples.WebClients.Examples.Api
|
||||
namespace GerstITS.Examples.WebClients.Examples.Api;
|
||||
|
||||
public sealed partial class Module : IIoCModule<IServiceCollection>
|
||||
{
|
||||
public sealed partial class Module : IIoCModule<IServiceCollection>
|
||||
#region IIoCModule
|
||||
|
||||
public void RegisterComponents(IServiceCollection container)
|
||||
{
|
||||
#region IIoCModule
|
||||
|
||||
public void RegisterComponents(IServiceCollection container)
|
||||
{
|
||||
RegisterConfigurations(container);
|
||||
RegisterCreationRules(container);
|
||||
}
|
||||
|
||||
#endregion
|
||||
RegisterConfigurations(container);
|
||||
RegisterCreationRules(container);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user