Closed
Description
Description
I have an EF model with two entities: User and Content. Created controllers etc according to getting-started documentation.
I wanted to override filtering for Content, so created custom classes:
public class ContentResourceService : EntityResourceService<Content, long> { }
public class ContentEntityRepository : DefaultEntityRepository<Content, long> { }
Registered them as described at https://json-api-dotnet.github.io/#/layer-overview:
services.AddScoped<IResourceService<Content, long>, ContentResourceService>();
services.AddScoped<IEntityRepository<Content, long>, ContentEntityRepository>();
Now getting a list of content works as expected, but getting a list of users returns:
{
"errors": [
{
"title": "InvalidCastException",
"detail": "Unable to cast object of type 'ApiFrameworkTryout2.Controllers.ContentResourceService' to type 'JsonApiDotNetCore.Services.IResourceService`2[ApiFrameworkTryout2.Models.User,System.Int64]'.",
"status": "500",
"meta": {
"stackTrace": [
"System.InvalidCastException: Unable to cast object of type 'ApiFrameworkTryout2.Controllers.ContentResourceService' to type 'JsonApiDotNetCore.Services.IResourceService`2[ApiFrameworkTryout2.Models.User,System.Int64]'.\r",
" at object lambda_method(Closure, IServiceProvider, object[])\r",
" at Func<ControllerContext, object> Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider.CreateActivator(ControllerActionDescriptor descriptor)+(ControllerContext controllerContext) => { }\r",
" at Func<ControllerContext, object> Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.CreateControllerFactory(ControllerActionDescriptor descriptor)+CreateController(ControllerContext controllerContext)\r",
" at Task Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)\r",
" at async Task Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()\r",
" at async Task Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()"
]
}
}
]
}
Version used: 4.0.0-alpha3