23
23
24
24
namespace JsonApiDotNetCore . Builders
25
25
{
26
+ /// <summary>
27
+ /// A utility class that builds a JsonApi application. It registers all required services
28
+ /// and allows the user to override parts of the startup configuration.
29
+ /// </summary>
26
30
public class JsonApiApplicationBuilder
27
31
{
28
32
public readonly JsonApiOptions JsonApiOptions = new JsonApiOptions ( ) ;
@@ -38,8 +42,17 @@ public JsonApiApplicationBuilder(IServiceCollection services, IMvcCoreBuilder mv
38
42
_mvcBuilder = mvcBuilder ;
39
43
}
40
44
45
+ /// <summary>
46
+ /// Executes the action provided by the user to configure <see cref="JsonApiOptions"/>
47
+ /// </summary>
41
48
public void ConfigureJsonApiOptions ( Action < JsonApiOptions > configureOptions ) => configureOptions ( JsonApiOptions ) ;
42
49
50
+ /// <summary>
51
+ /// Configures built-in .net core MVC (things like middleware, routing). Most of this configuration can be adjusted for the developers need.
52
+ /// Before calling .AddJsonApi(), a developer can register their own implementation of the following services to customize startup:
53
+ /// <see cref="IResourceGraphBuilder"/>, <see cref="IServiceDiscoveryFacade"/>, <see cref="IJsonApiExceptionFilterProvider"/>,
54
+ /// <see cref="IJsonApiTypeMatchFilterProvider"/>, <see cref="IJsonApiRoutingConvention"/> and <see cref="IResourceNameFormatter"/>.
55
+ /// </summary>
43
56
public void ConfigureMvc ( )
44
57
{
45
58
RegisterJsonApiStartupServices ( ) ;
@@ -63,16 +76,27 @@ public void ConfigureMvc()
63
76
_services . AddSingleton ( routingConvention ) ; // <--- why is this needed?
64
77
}
65
78
79
+ /// <summary>
80
+ /// Executes autodiscovery of JADNC services.
81
+ /// </summary>
66
82
public void AutoDiscover ( Action < IServiceDiscoveryFacade > autoDiscover )
67
83
{
68
84
autoDiscover ( _serviceDiscoveryFacade ) ;
69
85
}
70
86
87
+ /// <summary>
88
+ /// Executes the action provided by the user to configure the resources using <see cref="IResourceGraphBuilder"/>
89
+ /// </summary>
90
+ /// <param name="resourceGraphBuilder"></param>
71
91
public void ConfigureResources ( Action < IResourceGraphBuilder > resourceGraphBuilder )
72
92
{
73
93
resourceGraphBuilder ( _resourceGraphBuilder ) ;
74
94
}
75
95
96
+ /// <summary>
97
+ /// Executes the action provided by the user to configure the resources using <see cref="IResourceGraphBuilder"/>.
98
+ /// Additionally, inspects the EF core database context for models that implement IIdentifiable.
99
+ /// </summary>
76
100
public void ConfigureResources < TContext > ( Action < IResourceGraphBuilder > resourceGraphBuilder ) where TContext : DbContext
77
101
{
78
102
_resourceGraphBuilder . AddDbContext < TContext > ( ) ;
@@ -81,17 +105,9 @@ public void ConfigureResources<TContext>(Action<IResourceGraphBuilder> resourceG
81
105
resourceGraphBuilder ? . Invoke ( _resourceGraphBuilder ) ;
82
106
}
83
107
84
- private void RegisterJsonApiStartupServices ( )
85
- {
86
- _services . AddSingleton < IJsonApiOptions > ( JsonApiOptions ) ;
87
- _services . TryAddSingleton < IResourceNameFormatter > ( new KebabCaseFormatter ( ) ) ;
88
- _services . TryAddSingleton < IJsonApiRoutingConvention , DefaultRoutingConvention > ( ) ;
89
- _services . TryAddSingleton < IResourceGraphBuilder , ResourceGraphBuilder > ( ) ;
90
- _services . TryAddSingleton < IServiceDiscoveryFacade > ( sp => new ServiceDiscoveryFacade ( _services , sp . GetRequiredService < IResourceGraphBuilder > ( ) ) ) ;
91
- _services . TryAddScoped < IJsonApiExceptionFilterProvider , JsonApiExceptionFilterProvider > ( ) ;
92
- _services . TryAddScoped < IJsonApiTypeMatchFilterProvider , JsonApiTypeMatchFilterProvider > ( ) ;
93
- }
94
-
108
+ /// <summary>
109
+ /// Registers the remaining internals.
110
+ /// </summary>
95
111
public void ConfigureServices ( )
96
112
{
97
113
var resourceGraph = _resourceGraphBuilder . Build ( ) ;
@@ -154,7 +170,6 @@ public void ConfigureServices()
154
170
_services . AddScoped < IInverseRelationships , InverseRelationships > ( ) ;
155
171
}
156
172
157
-
158
173
private void AddQueryParameterServices ( )
159
174
{
160
175
_services . AddScoped < IIncludeService , IncludeService > ( ) ;
@@ -174,7 +189,6 @@ private void AddQueryParameterServices()
174
189
_services . AddScoped < IQueryParameterService > ( sp => sp . GetService < IOmitNullService > ( ) ) ;
175
190
}
176
191
177
-
178
192
private void AddResourceHooks ( )
179
193
{
180
194
_services . AddSingleton ( typeof ( IHooksDiscovery < > ) , typeof ( HooksDiscovery < > ) ) ;
@@ -196,5 +210,16 @@ private void AddServerSerialization()
196
210
_services . AddScoped ( sp => sp . GetRequiredService < IJsonApiSerializerFactory > ( ) . GetSerializer ( ) ) ;
197
211
_services . AddScoped < IResourceObjectBuilder , ResponseResourceObjectBuilder > ( ) ;
198
212
}
213
+
214
+ private void RegisterJsonApiStartupServices ( )
215
+ {
216
+ _services . AddSingleton < IJsonApiOptions > ( JsonApiOptions ) ;
217
+ _services . TryAddSingleton < IResourceNameFormatter > ( new KebabCaseFormatter ( ) ) ;
218
+ _services . TryAddSingleton < IJsonApiRoutingConvention , DefaultRoutingConvention > ( ) ;
219
+ _services . TryAddSingleton < IResourceGraphBuilder , ResourceGraphBuilder > ( ) ;
220
+ _services . TryAddSingleton < IServiceDiscoveryFacade > ( sp => new ServiceDiscoveryFacade ( _services , sp . GetRequiredService < IResourceGraphBuilder > ( ) ) ) ;
221
+ _services . TryAddScoped < IJsonApiExceptionFilterProvider , JsonApiExceptionFilterProvider > ( ) ;
222
+ _services . TryAddScoped < IJsonApiTypeMatchFilterProvider , JsonApiTypeMatchFilterProvider > ( ) ;
223
+ }
199
224
}
200
225
}
0 commit comments