This file contains 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
{ | |
"$schema": "https://json.schemastore.org/launchsettings.json", | |
"profiles": { | |
"WebApp.Api": { | |
"commandName": "Project", | |
"dotnetRunMessages": true, | |
"launchBrowser": true, | |
"launchUrl": "api-docs", | |
"applicationUrl": "https://localhost:7224;http://localhost:5075", | |
"environmentVariables": { |
This file contains 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
app.UseReDoc(options => | |
{ | |
options.DocumentTitle = "ReDoc Sample Project"; | |
options.SpecUrl = "/swagger/v1/swagger.json"; | |
}); |
This file contains 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
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>)); | |
services.AddTransient(typeof(IRequestExceptionHandler<,,>), typeof(ExceptionHandlingBehavior<,,>)); | |
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>)); |
This file contains 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 LoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> | |
{ | |
private readonly ILogger<TRequest> logger; | |
public LoggingBehavior(ILogger<TRequest> logger) | |
{ | |
this.logger = logger; | |
} | |
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next) |
This file contains 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 ExceptionHandlingBehavior<TRequest, TResponse, TException> : IRequestExceptionHandler<TRequest, TResponse, TException> | |
where TRequest : notnull | |
where TException : Exception | |
where TResponse : notnull, ServiceResponse | |
{ | |
private readonly ILogger<ExceptionHandlingBehavior<TRequest, TResponse, TException>> logger; | |
public ExceptionHandlingBehavior( | |
ILogger<ExceptionHandlingBehavior<TRequest, TResponse, TException>> logger) | |
{ |
This file contains 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 ValidationBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> | |
where TRequest : IRequest<TResponse> | |
where TResponse : ServiceResponse, new() | |
{ | |
private readonly IEnumerable<IValidator<TRequest>> validators; | |
public ValidationBehavior(IEnumerable<IValidator<TRequest>> validators) | |
{ | |
this.validators = validators; |
This file contains 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
[HttpGet("{id}")] | |
[ProducesResponseType(typeof(ServiceResponse), (int) HttpStatusCode.BadRequest)] | |
[ProducesResponseType(typeof(ServiceResponse), (int) HttpStatusCode.NotFound)] | |
[ProducesResponseType(typeof(ServiceResponse), (int) HttpStatusCode.OK)] | |
public async Task<IActionResult> Get(int id) | |
{ | |
if (id <= 0) | |
{ | |
return BadRequest(Messages.InvalidRequest); | |
} |
This file contains 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 GetSampleByIdQuery : IRequest<ServiceResponse> | |
{ | |
public int Id { get; set; } | |
public GetSampleByIdQuery(int id) | |
{ | |
Id = id; | |
} | |
} |
This file contains 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 GetSampleByIdHandler : IRequestHandler<GetSampleByIdQuery, ServiceResponse> | |
{ | |
private readonly IReadOnlyRepository<Sample> repository; | |
public GetSampleByIdHandler(IReadOnlyRepository<Sample> repository) | |
{ | |
this.repository = repository; | |
} | |
public async Task<ServiceDataResponse> Handle(GetSampleByIdQuery request, CancellationToken cancellationToken) |
This file contains 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 interface ISampleService | |
{ | |
ServiceDataResult GetAll(); | |
ServiceDataResult Get(string id); | |
ServiceResult Add(AddSampleRequest request); | |
ServiceResult Update(UpdateSampleRequest request); | |
ServiceResult Delete(string id); | |
} | |
public class SampleService : ISampleService |
NewerOlder