|
1 | | -using JsonApiDotNetCore.Internal; |
2 | 1 | using JsonApiDotNetCore.Middleware; |
3 | 2 | using Microsoft.AspNetCore.Builder; |
4 | | -using Microsoft.Extensions.DependencyInjection; |
5 | 3 |
|
6 | 4 | namespace JsonApiDotNetCore |
7 | 5 | { |
8 | 6 | public static class ApplicationBuilderExtensions |
9 | 7 | { |
10 | 8 | /// <summary> |
11 | | - /// Validates the resource graph and optionally registers the JsonApiDotNetCore middleware. |
| 9 | + /// Registers the JsonApiDotNetCore middleware. |
12 | 10 | /// </summary> |
13 | | - /// <remarks> |
14 | | - /// The <paramref name="skipRegisterMiddleware"/> can be used to skip any middleware registration, in which case the developer |
15 | | - /// is responsible for registering required middleware. |
16 | | - /// </remarks> |
17 | | - /// <param name="app"></param> |
18 | | - /// <param name="skipRegisterMiddleware">Indicates to not register any middleware. This enables callers to take full control of middleware registration order.</param> |
19 | | - /// <param name="useAuthentication">Indicates if 'app.UseAuthentication()' should be called. Ignored when <paramref name="skipRegisterMiddleware"/> is set to true.</param> |
20 | | - /// <param name="useAuthorization">Indicates if 'app.UseAuthorization()' should be called. Ignored when <paramref name="skipRegisterMiddleware"/> is set to true.</param> |
| 11 | + /// <param name="builder">The <see cref="IApplicationBuilder"/> to add the middleware to.</param> |
21 | 12 | /// <example> |
22 | | - /// The next example illustrates how to manually register middleware. |
23 | | - /// <code> |
24 | | - /// app.UseJsonApi(skipRegisterMiddleware: true); |
| 13 | + /// The code below is the minimal that is required for proper activation, |
| 14 | + /// which should be added to your Startup.Configure method. |
| 15 | + /// <code><![CDATA[ |
25 | 16 | /// app.UseRouting(); |
26 | | - /// app.UseMiddleware{JsonApiMiddleware}(); |
| 17 | + /// app.UseJsonApi(); |
27 | 18 | /// app.UseEndpoints(endpoints => endpoints.MapControllers()); |
28 | | - /// </code> |
| 19 | + /// ]]></code> |
29 | 20 | /// </example> |
30 | | - public static void UseJsonApi(this IApplicationBuilder app, bool skipRegisterMiddleware = false, bool useAuthentication = false, bool useAuthorization = false) |
| 21 | + public static void UseJsonApi(this IApplicationBuilder builder) |
31 | 22 | { |
32 | | - using (var scope = app.ApplicationServices.CreateScope()) |
33 | | - { |
34 | | - var inverseRelationshipResolver = scope.ServiceProvider.GetService<IInverseRelationships>(); |
35 | | - inverseRelationshipResolver?.Resolve(); |
36 | | - } |
37 | | - |
38 | | - if (!skipRegisterMiddleware) |
39 | | - { |
40 | | - // An endpoint is selected and set on the HttpContext if a match is found |
41 | | - app.UseRouting(); |
42 | | - |
43 | | - if (useAuthentication) |
44 | | - { |
45 | | - app.UseAuthentication(); |
46 | | - } |
47 | | - |
48 | | - if (useAuthorization) |
49 | | - { |
50 | | - app.UseAuthorization(); |
51 | | - } |
52 | | - |
53 | | - // middleware to run after routing occurs. |
54 | | - app.UseMiddleware<JsonApiMiddleware>(); |
55 | | - |
56 | | - // Executes the endpoints that was selected by routing. |
57 | | - app.UseEndpoints(endpoints => endpoints.MapControllers()); |
58 | | - } |
| 23 | + builder.UseMiddleware<JsonApiMiddleware>(); |
59 | 24 | } |
60 | 25 | } |
61 | 26 | } |
0 commit comments