This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class CreateCustomerHandler : IRequestHandler<CreateCustomer, Guid> | |
| { | |
| private readonly NotificationContext _notificationContext; | |
| private readonly ICustomerRepository _customerRepository; | |
| public CreateCustomerHandler( | |
| NotificationContext notificationContext, | |
| ICustomerRepository customerRepository) | |
| { | |
| _notificationContext = notificationContext; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public abstract class Entity | |
| { | |
| public Guid Id { get; protected set; } | |
| public bool Valid { get; private set; } | |
| public bool Invalid => !Valid; | |
| public ValidationResult ValidationResult { get; private set; } | |
| public bool Validate<TModel>(TModel model, AbstractValidator<TModel> validator) | |
| { | |
| ValidationResult = validator.Validate(model); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Notification | |
| { | |
| public string Key { get; } | |
| public string Message { get; } | |
| public Notification(string key, string message) | |
| { | |
| Key = key; | |
| Message = message; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Customer | |
| { | |
| public string Name { get; } | |
| public string Email { get; } | |
| public Customer(string name, string email) | |
| { | |
| if (string.IsNullOrEmpty(name)) | |
| { | |
| throw new InvalidOperationException("Name cannot be empty"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Route("api/[controller]")] | |
| [ApiController] | |
| public class ValuesController : ControllerBase | |
| { | |
| private readonly FakeData _data; | |
| public ValuesController(FakeData data) | |
| { | |
| _data = data; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class GlobalExceptionHandlerMiddleware : IMiddleware | |
| { | |
| private readonly ILogger<GlobalExceptionHandlerMiddleware> _logger; | |
| public GlobalExceptionHandlerMiddleware(ILogger<GlobalExceptionHandlerMiddleware> logger) | |
| { | |
| _logger = logger; | |
| } | |
| public async Task InvokeAsync(HttpContext context, RequestDelegate next) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class ExceptionHandlerExtensions | |
| { | |
| public static void UseGlobalExceptionHandler(this IApplicationBuilder app, ILoggerFactory loggerFactory) | |
| { | |
| app.UseExceptionHandler(builder => | |
| { | |
| builder.Run(async context => | |
| { | |
| var exceptionHandlerFeature = context.Features.Get<IExceptionHandlerFeature>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Startup | |
| { | |
| public IConfiguration Configuration { get; } | |
| public void ConfigureServices(IServiceCollection services) | |
| { | |
| services.AddLogging(); | |
| services.AddSingleton(Configuration); | |
| services.AddTransient<IStartupFilter, ConfigurationSettingValidationStartupFilter>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ConfigurationSettingValidationStartupFilter : IStartupFilter | |
| { | |
| private readonly IEnumerable<ConfigurationSettings> _configurationSettings; | |
| private readonly ILogger<ConfigurationSettingValidationStartupFilter> _logger; | |
| public ConfigurationSettingValidationStartupFilter( | |
| IEnumerable<ConfigurationSettings> configurationSettings, | |
| ILogger<ConfigurationSettingValidationStartupFilter> logger) | |
| { | |
| _configurationSettings = configurationSettings; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public abstract class ConfigurationSettings | |
| { | |
| public List<ValidationResult> ValidationResult = new List<ValidationResult>(); | |
| public bool Validate() => Validator.TryValidateObject( | |
| this, | |
| new ValidationContext(this), | |
| ValidationResult, | |
| true); | |
| } |