kahbazi / mediatr.aspnetcore.endpoints Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
How can I add my input validations when I use this library?
As I see in the code, the deserialization exceptions (JsonException..) is swallowed. There is no Log entry written and the exception is not re-thrown. So When the exception happens, we only get Status Code 400 but not error why.
Is it possible to use authentication and authorization?
I'm seeing an error when using a System.Guid
type route parameter:
Sample code:
namespace Test2
{
public class SampleRequest2 : IRequest<SampleResponse2>
{
public Guid Id { get; set; }
}
public class SampleResponse2
{
public Guid Id { get; set; }
public DateTime Timestamp { get; set; }
}
[ApiController]
public class SampleRequestHandler : IRequestHandler<SampleRequest2, SampleResponse2>
{
[HttpGet("Test/{id}")]
public async Task<SampleResponse2> Handle([FromRoute] SampleRequest2 request, CancellationToken cancellationToken)
{
return new SampleResponse2
{
Id = request.Id,
Timestamp = DateTime.Now
};
}
}
}
Error message:
System.InvalidCastException: Invalid cast from 'System.String' to 'System.Guid'.
at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
at System.String.System.IConvertible.ToType(Type type, IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType)
at MediatR.AspNetCore.Endpoints.EndpointRouteBuilderExtensions.MapRouteData(IMediatorEndpointMetadata requestMetadata, RouteData routeData, Object model)
at MediatR.AspNetCore.Endpoints.EndpointRouteBuilderExtensions.MediatorRequestDelegate(HttpContext context)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Serilog.AspNetCore.RequestLoggingMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
I'm using MediatR v9.0.0 which has separated the IMediatR interface into ISender and IPublisher which I think is a breaking change.
Would you consider updating this package to support the latest MediatR?
I can't seem to make a GET request pick up query parameters:
Sample code:
using System;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using Microsoft.AspNetCore.Mvc;
namespace Test
{
public class SampleRequest : IRequest<SampleResponse>
{
public int Id { get; set; }
}
public class SampleResponse
{
public int Id { get; set; }
public DateTime Timestamp { get; set; }
}
[ApiController]
public class SampleRequestHandler : IRequestHandler<SampleRequest, SampleResponse>
{
[HttpGet("Test")]
public async Task<SampleResponse> Handle([FromQuery]SampleRequest request, CancellationToken cancellationToken)
{
return new SampleResponse
{
Id = request.Id,
Timestamp = DateTime.Now
};
}
}
}
Currently all handlers are registered as Endpoint. Maybe make this line an optin/out option to only register handlers that have a HttpMethodAttribute.
Currently, there is no way to configure the Syste.Text.Json serializer, this leads to camel case data sent from most SPA apps not be deserialized properly, we need some way to configure this or have at least
new JsonSerializerOptions { PropertyNameCaseInsensitive = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase }
in the EndpointRouteBuilderExtensions.cs
Just wondering if there is any interest in brining this project to .net6 using Source Generator and Minimal Api?
Considering Mvc seems to be on the back burner now.
Would be nice to add an overload just like you can with AddMedaitR(assemblies);
AddMediatREndpoints(params Assembly[] assemblies)
Thanks
Hi.
When I use standard controllers, the swagger documentation generates a request body examples from model (dto) classes. In case of MediatrEndpoints those body examples are not generated.
In the attached picture I can see Request body example
But in MediatR.Endpoints that schema is not generated.
How can I tell it to generate the Request body schema?
Any tips how to extend this library with the standard Authorize attribute in combination with IAuthorizationService?
Any tips how to map values from the Url and/or querystring on the Request Type object?
public class ViewEntityRequest : IRequest<ViewEntityRequest.Response> {
public long Id { get; set; }
public string Type { get; set; }
}
[HttpGet("view/{type}/{id}")]
Sample get request with url: /view/entity/5
Thanks
Marco
Hi!
I was trying to create a custom route apart from the Request class name. But I couldn't find any solution. Then I debugged the open API sample and found this.
https://github.com/Kahbazi/MediatR.AspNetCore.Endpoints/blob/develop/src/MediatR.AspNetCore.Endpoints/OpenApi/MediatorEndpointApiDescriptionGroupCollectionProvider.cs#L42
Apart from that, is there any particular reason to use Nswag instead of Swashbuckle?
Thanks in advance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.