Giter Site home page Giter Site logo

jonpsmith / efcore.genericservices.aspnetcore Goto Github PK

View Code? Open in Web Editor NEW
49.0 49.0 13.0 120 KB

Converts EFCore.GenericServices and EfCore.GenericBizRunner statuses to ASP.NET Core formats

Home Page: https://www.thereformedprogrammer.net/how-to-write-good-testable-asp-net-core-web-api-code-quickly/

License: MIT License

C# 100.00%

efcore.genericservices.aspnetcore's People

Contributors

jonpsmith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

efcore.genericservices.aspnetcore's Issues

Converting IStatusGeneric to ProblemDetails

Is there any work in progress to support converting IStatusGeneric to ProblemDetails? Or an alternate package that does? It doesn't really make sense to use the ASP.NET 2.1 format for new APIs.

Accessing DTO mappers

This is question about EfCore.GenericServices and EfCore.GenericBizRunner but in the context of ASP NET Core app so Im asking here.

Let's say I have a Post endpoint which takes in a CreateTodoDto model, similar to the example, but instead of returning a CreatedAt response with a TodoItemresult, I want to return a TodoItemDto model as an abstraction over the database entity.

I changed the ICreateTodoBizLogic to return a TodoItemDto, however I find myself having to manually build the DTO to be returned. How can I take advantage of the fact that I have used ILinkToEntity<TodoItem> and access the mapper that has already been setup?

In a similar vein, how can I take advantage of CreateTodoDto being linked to TodoItem to automatically populate properties of TodoItem rather than building from scratch inside the BizAction method?

Hope this makes sense, thanks in advance for your response.

Asp.Net Core 2.2 Reference causing Mvc Analyzer errors

Hi Jon, thank you for your work with these libraries.
I was wondering if there is a reason you reference ASP.Net Core 2.2 and not > 2.2? With 2.2 references in a 3.1 project I am getting Analyzer errors (due to the Microsoft.AspNetCore.Mvc.Analyzers being referenced. Does it have to do with framework references? To get around this with a 3.1 project, is it best to simply duplicate your code in our project?

Perhaps I am missing something, I would very happy to hear your thoughts on this.

Error is like so:
>CSC : warning AD0001: Analyzer 'Microsoft.AspNetCore.Mvc.Analyzers.TopLevelParameterNameAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.

Doesn't work with GenericServices 3.1.0

I updated the GenericServices and GenericBizRunner packages to 3.1.0 and this library doesn't work anymore. I get the following error:

Reference to type 'IStatusGeneric' claims it is defined in 'GenericServices', but it could not be found

Writing to the response body is invalid for responses with status code 204.

Using in .NET Core 3.1

EfCore.GenericBizRunner 4.0.0
EfCore.GenericServices.AspNetCore 4.0.0

The following code

        [HttpGet("{id}", Name = "GetSingleRelation")]
        public async Task<ActionResult<WebApiMessageAndResult<RelationEntity>>> GetSingleAsync(Guid id, [FromServices]ICrudServicesAsync<DataDbContext> service)
        {
            var relation = await service.ReadSingleAsync<RelationEntity>(id);
            return service.Response(relation);
        }

service.Response(null) says

This will return a result value, with the status Message 1. If there are no errors and the result is not null it will return a HTTP 200 response plus a json containing the message from the status and the results object 2. If there are no errors but result is null it will return a HTTP 204 (NoContent) with the status Message 3. If there are errors it returns a HTTP 400 with the error information in the standard WebAPI format

However null results into the following exception:

System.InvalidOperationException: Writing to the response body is invalid for responses with status code 204.
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ThrowWritingToResponseBodyNotSupported()
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.FirstWriteAsyncInternal(ReadOnlyMemory1 data, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.FirstWriteAsync(ReadOnlyMemory1 data, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.WritePipeAsync(ReadOnlyMemory1 data, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponseStream.WriteAsync(ReadOnlyMemory1 source, CancellationToken cancellationToken)
at System.Text.Json.JsonSerializer.WriteAsyncCore(Stream utf8Json, Object value, Type inputType, JsonSerializerOptions options, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|21_0(ResourceInvoker invoker, IActionResult result)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|29_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)
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 Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

I have removed all formatters and just using a clean "UseMVC()" in my startup.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.