-
-
Notifications
You must be signed in to change notification settings - Fork 158
Add optional params to control middleware #665
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
Changes from all commits
47cfdb5
c0c5fe6
9f13082
54ea051
7c8a0cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,11 +15,27 @@ namespace JsonApiDotNetCore.Extensions | |
public static class IApplicationBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Adds necessary components such as routing to your application | ||
/// Runs several internal JsonApiDotNetCore services to ensure proper configuration and registers required middlewares. | ||
/// The <paramref name="skipRegisterMiddleware"/> can be used to skip any middleware registration, in which case the developer is | ||
/// is responsible for registering middleware that are required for JsonApiDotNetCore. | ||
/// </summary> | ||
/// <param name="app"></param> | ||
/// <returns></returns> | ||
public static void UseJsonApi(this IApplicationBuilder app) | ||
/// <param name="skipRegisterMiddleware">Indicates if JsonApiDotNetCore should skip middleware registration. This enabl.</param> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. half sentence. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one I noticed too, did a hotfix in ebaa091. If you could squeeze the removal of the 2nd "is" in one of your upcoming PRs would be appreciated :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in #684. |
||
/// <param name="useAuthentication">Indicates if .NET Core authentication middleware should be registered. Ignored when <paramref name="skipRegisterMiddleware"/> is set to true.</param> | ||
/// <param name="useAuthorization">Indicates if .NET Core authentication middleware should be registered. Ignored when <paramref name="skipRegisterMiddleware"/> is set to true.</param> | ||
/// <example> | ||
/// This example illustrate which required middlewares should be registered when using the <paramref name="skipRegisterMiddleware"/> option. | ||
/// <code> | ||
/// app.UseJsonApi(skipRegisterMiddleware: true); | ||
/// // JADNC requires routing | ||
/// app.UseRouting(); | ||
/// // JADNC requires CurrentRequestMiddleware | ||
/// app.UseMiddleware<CurrentRequestMiddleware>(); | ||
/// // JANDC requires the endpoint feature enabled as follows | ||
/// app.UseEndpoints(endpoints => endpoints.MapControllers()); | ||
/// </code> | ||
/// </example> | ||
public static void UseJsonApi(this IApplicationBuilder app, bool skipRegisterMiddleware = false, bool useAuthentication = false, bool useAuthorization = false) | ||
{ | ||
LogResourceGraphValidations(app); | ||
using (var scope = app.ApplicationServices.CreateScope()) | ||
|
@@ -28,14 +44,26 @@ public static void UseJsonApi(this IApplicationBuilder app) | |
inverseRelationshipResolver?.Resolve(); | ||
} | ||
|
||
// An endpoint is selected and set on the HttpContext if a match is found | ||
app.UseRouting(); | ||
if (!skipRegisterMiddleware) { | ||
// An endpoint is selected and set on the HttpContext if a match is found | ||
app.UseRouting(); | ||
|
||
// middleware to run after routing occurs. | ||
app.UseMiddleware<CurrentRequestMiddleware>(); | ||
if (useAuthentication) | ||
{ | ||
app.UseAuthentication(); | ||
}; | ||
|
||
// Executes the endpoints that was selected by routing. | ||
app.UseEndpoints(endpoints => endpoints.MapControllers()); | ||
if (useAuthorization) | ||
{ | ||
app.UseAuthorization(); | ||
}; | ||
|
||
// middleware to run after routing occurs. | ||
app.UseMiddleware<CurrentRequestMiddleware>(); | ||
|
||
// Executes the endpoints that was selected by routing. | ||
app.UseEndpoints(endpoints => endpoints.MapControllers()); | ||
} | ||
} | ||
|
||
/// <summary> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"is" twice