mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Adds editorconfig and refactors to the established rules
This commit is contained in:
1 parent
712a0f2b27
commit
cd44f11d9e
138 files changed
+1799
-1629
No files matched your search
@@ -44,12 +44,12 @@ public class ValidationBehavior<TRequest, TResponse> : IPipelineBehavior<TReques
|
||||
if (_validator is null)
|
||||
return await next(request, cancellationToken).ConfigureAwait(false);
|
||||
// before the handler of the command is executed
|
||||
var validationResult = await _validator.ValidateAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
FluentValidation.Results.ValidationResult validationResult = await _validator.ValidateAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
// if there are no validation errors, invoke the command handler
|
||||
if (validationResult.IsValid)
|
||||
return await next(request, cancellationToken).ConfigureAwait(false);
|
||||
// after the command handler is executed
|
||||
var errors = validationResult.Errors.ConvertAll(validationFailure => Error.Validation(description: validationFailure.ErrorMessage));
|
||||
System.Collections.Generic.List<Error> errors = validationResult.Errors.ConvertAll(validationFailure => Error.Validation(description: validationFailure.ErrorMessage));
|
||||
// the compiler doesn't know there is an implicit converter from a list of errors to the ErrorOr object, and unfortunately, there is no way around this but to use some magic
|
||||
// this is acceptable because we DO know that we will always have a list of errors of type ErrorOr (check the generic constraint at the top of the class!)
|
||||
return (dynamic)errors;
|
||||
|
||||
@@ -25,7 +25,7 @@ public class OptionalJsonConverter<TValue> : JsonConverter<Optional<TValue>>
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.Null)
|
||||
return Optional<TValue>.None();
|
||||
var value = JsonSerializer.Deserialize<TValue>(ref reader, options);
|
||||
TValue? value = JsonSerializer.Deserialize<TValue>(ref reader, options);
|
||||
return Optional<TValue>.Some(value!);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,9 +20,7 @@ public class OptionalJsonConverterFactory : JsonConverterFactory
|
||||
/// <returns><see langword="true"/> if the type is <see cref="Optional{TValue}"/>, <see langword="false"/> otherwise.</returns>
|
||||
public override bool CanConvert(Type typeToConvert)
|
||||
{
|
||||
if (!typeToConvert.IsGenericType)
|
||||
return false;
|
||||
return typeToConvert.GetGenericTypeDefinition() == typeof(Optional<>);
|
||||
return typeToConvert.IsGenericType && typeToConvert.GetGenericTypeDefinition() == typeof(Optional<>);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation;
|
||||
using Lumina.Application.Common.Behaviors;
|
||||
using Mapster;
|
||||
using MapsterMapper;
|
||||
using Mediator;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using FluentValidation;
|
||||
using MapsterMapper;
|
||||
using Mapster;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DependencyInjection;
|
||||
@@ -23,10 +23,7 @@ public static class ApplicationLayerServices
|
||||
public static IServiceCollection AddApplicationLayerServices(this IServiceCollection services)
|
||||
{
|
||||
// register Mediator
|
||||
services.AddMediator(options =>
|
||||
{
|
||||
options.ServiceLifetime = ServiceLifetime.Scoped;
|
||||
});
|
||||
services.AddMediator(options => options.ServiceLifetime = ServiceLifetime.Scoped);
|
||||
|
||||
// register the validation behavior
|
||||
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
|
||||
@@ -35,7 +32,7 @@ public static class ApplicationLayerServices
|
||||
services.AddValidatorsFromAssembly(typeof(ApplicationLayerServices).Assembly);
|
||||
|
||||
// register mapster configs in this assembly
|
||||
var mapsterConfig = TypeAdapterConfig.GlobalSettings;
|
||||
TypeAdapterConfig mapsterConfig = TypeAdapterConfig.GlobalSettings;
|
||||
mapsterConfig.Scan(typeof(ApplicationLayerServices).Assembly);
|
||||
services.AddSingleton(mapsterConfig);
|
||||
services.AddScoped<IMapper, ServiceMapper>();
|
||||
|
||||
+2
-2
@@ -108,7 +108,7 @@ public class BookMappingConfig : IRegister
|
||||
Optional<BookFormat>.FromNullable(!string.IsNullOrWhiteSpace(src.Format) ? Enum.Parse<BookFormat>(src.Format) : default),
|
||||
Optional<string>.FromNullable(src.Edition),
|
||||
Optional<int>.FromNullable(src.VolumeNumber),
|
||||
Optional<BookSeries>.None(),
|
||||
Optional<BookSeries>.None(),
|
||||
Optional<string>.FromNullable(src.ASIN),
|
||||
Optional<string>.FromNullable(src.GoodreadsId),
|
||||
Optional<string>.FromNullable(src.LCCN),
|
||||
@@ -121,7 +121,7 @@ public class BookMappingConfig : IRegister
|
||||
src.Created,
|
||||
Optional<DateTime>.FromNullable(src.Updated),
|
||||
src.ISBNs.Select(i => Isbn.Create(i.Value!, i.Format ?? default).Value).ToList(),
|
||||
new List<MediaContributorId>(),
|
||||
new List<MediaContributorId>(),
|
||||
src.Ratings.Select(r => BookRating.Create(
|
||||
r.Value ?? default,
|
||||
r.MaxValue ?? default,
|
||||
|
||||
Reference in new issue
Block a user