Skip to content

Routing does not respect custom pluralized resource name #805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 53 commits into from
Sep 10, 2020
Merged

Conversation

maurei
Copy link
Member

@maurei maurei commented Aug 26, 2020

Closes #786
Closes #807

JsonApiRoutingConvention now depends on IResourceGraph rather than ResourceNameFormatter. As a result:

  • the publicResourceName argument in AddResource<T>( ... ) is now respected, see my comment in PluralizedTypeName option when adding resource doesn't work for routing #786.
  • ResourceNameFormatter was called twice in different places doing the exact same thing. This bit of duplicated code is refactored.
  • the internal flow with the intermediate service providers has been altered a little bit: we now need a second temporary service provider, one for configuration of the resource graph, and one for the configuration of the middleware which depends on the resource graph (i.e. JsonApiRoutingConvention, specifically)
  • the flow of service and resources auto-discovery has been altered a little bit: the discovery of resources vs any other JANDC service is split in two separate stages. This prevents all JADNC services being registered available to the intermediate service providers which do not require them: in this phase a small set of startup services and JADNC resources are only really required

@maurei maurei marked this pull request as ready for review August 26, 2020 09:38
@maurei maurei requested a review from bart-degreed August 26, 2020 09:38
@maurei maurei marked this pull request as draft August 26, 2020 09:44
@maurei maurei marked this pull request as ready for review August 26, 2020 09:52
@bart-degreed bart-degreed changed the title Fix/786 Routing does not respect custom pluralized type name for a resource Aug 26, 2020
@bart-degreed bart-degreed changed the title Routing does not respect custom pluralized type name for a resource Routing does not respect custom pluralized resource name Aug 26, 2020
Copy link
Contributor

@bart-degreed bart-degreed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See review feedback. In general, these types are mixing a lot of concerns and are deeply independent on each other, which makes it hard to track what is going on. But this was already the case, I'm not asking you to clean that up.

@bart-degreed
Copy link
Contributor

I think this PR should address #807 as well. Docs are fully up-to-date and verified right now, so I don't see why it should be postponed.

@bart-degreed
Copy link
Contributor

bart-degreed commented Aug 26, 2020

Another question: can you confirm that #800 (comment) still holds?

@maurei
Copy link
Member Author

maurei commented Aug 27, 2020

Another question: can you confirm that #800 (comment) still holds?

No: it this has not been the case for a long while now. The mapping between resources/routes/controllers is handled by IJsonApiRoutingConvention, also see IControllerResourceMapping which it inherits. Docs need to be updated on this, I'll put some work in #807

@maurei maurei mentioned this pull request Aug 27, 2020
maurei added 2 commits August 27, 2020 18:16
Rephrasing
fix example

fix: bump appveyor build

fix: undo c# 8 syntax for using statements

fix: attempt to fix win dispose bug

fix: bump build

fix: appveyor bump

fix: appveyor build fix final
Comment on lines 50 to 83
public class Startup
{
private Action<MvcOptions> _postConfigureMvcOptions;

public void ConfigureServices(IServiceCollection services)
{
...

var builder = services.AddMvcCore();
services.AddJsonApi<AppDbContext>( ... , mvcBuilder: builder);
mvcCoreBuilder.AddMvcOptions(x =>
{
// execute the mvc configuration callback after the JsonApiDotNetCore callback as been executed.
_postConfigureMvcOptions?.Invoke(x);
});

...
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment environment)
{

...

// Using a callback, we can defer to later (when service collection has become available).
_postConfigureMvcOptions = mvcOptions =>
{
mvcOptions.Filters.Clear();
mvcOptions.Filters.Insert(0, app.ApplicationServices.GetService<CustomFilter>());
};

...
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You put the call to app.UseJsonApi() in the wrong place. And didn't fix the white space.

Copy link
Contributor

@bart-degreed bart-degreed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments. I've resolved the fixed items. What's still open is not yet addressed,

@bart-degreed bart-degreed merged commit 54727c9 into master Sep 10, 2020
@bart-degreed bart-degreed deleted the fix/786 branch September 10, 2020 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants