Skip to content

Instantly share code, notes, and snippets.

View wellingtonjhn's full-sized avatar

Wellington Nascimento wellingtonjhn

View GitHub Profile
@wellingtonjhn
wellingtonjhn / mediatr-controller.cs
Last active April 9, 2018 03:55
ASP.Net Core Controller - MediatR
[Route("api/[controller]")]
public class AccountsController : Controller
{
private readonly IMediator _mediator;
public AccountsController(IMediator mediator)
{
_mediator = mediator;
}
@wellingtonjhn
wellingtonjhn / Startup.cs
Last active April 3, 2018 23:02
ASP.Net Startup MediatR DI
public class Startup
{
// ... restante do arquivo
public void ConfigureServices(IServiceCollection services)
{
AddApplicationServices(services);
services.AddMvc();
}
@wellingtonjhn
wellingtonjhn / CreateUserRequest.cs
Last active April 3, 2018 23:00
MediatR Request - Validator
public class CreateUser : IRequest<Response>
{
public string Name { get; }
public string Email { get; }
public string Password { get; }
public string ConfirmPassword { get; }
public CreateUser(string name, string email, string password, string confirmPassword)
{
Name = name;
@wellingtonjhn
wellingtonjhn / mediatr-failfast-behavior.cs
Created April 3, 2018 22:55
MediatR FailFaxt Behavior FluentValidation
public class FailFastRequestBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
where TRequest : IRequest<TResponse> where TResponse : Response
{
private readonly IEnumerable<IValidator> _validators;
public FailFastRequestBehavior(IEnumerable<IValidator<TRequest>> validators)
{
_validators = validators;
}
@wellingtonjhn
wellingtonjhn / 1.mediatr-pipeline-behavior.cs
Last active September 16, 2022 23:45
MediatR Pipeline Behavior
public class LoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
{
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{
await Logger.InfoAsync($"Handling {typeof(TRequest).Name}");
var response = await next();
await Logger.InfoAsync($"Handled {typeof(TResponse).Name}");
@wellingtonjhn
wellingtonjhn / 1.mediatr-startup.cs
Created March 29, 2018 23:09
MediatR Dependency Injection
public void ConfigureServices(IServiceCollection services)
{
services.AddMediatR();
}
@wellingtonjhn
wellingtonjhn / 1.mediatr-controllers.cs
Last active March 29, 2018 23:32
ASP.Net Controllers with MediatR
[Route("api/[controller]")]
public class AccountsController : Controller
{
private readonly IMediator _mediator;
public AccountsController(IMediator mediator)
{
_mediator = mediator;
}
@wellingtonjhn
wellingtonjhn / 1.mediatr-request-with-response.cs
Last active March 29, 2018 05:16
MediatR Request with Response
public class Ping : IRequest<string>
{
}
@wellingtonjhn
wellingtonjhn / 1.mediatr-request.cs
Last active March 29, 2018 05:16
MediatR Simple Requests
public class OneWay : IRequest
{
}
@wellingtonjhn
wellingtonjhn / CustomCompressionProvider.cs
Created March 10, 2018 07:43
Custom Response Compression ASP.Net Core
public class CustomCompressionProvider : ICompressionProvider
{
public string EncodingName => "mycustomcompression";
public bool SupportsFlush => true;
public Stream CreateStream(Stream outputStream)
{
return outputStream;
}
}