2323
2424namespace JsonApiDotNetCore . Builders
2525{
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>
2630 public class JsonApiApplicationBuilder
2731 {
2832 public readonly JsonApiOptions JsonApiOptions = new JsonApiOptions ( ) ;
@@ -38,8 +42,17 @@ public JsonApiApplicationBuilder(IServiceCollection services, IMvcCoreBuilder mv
3842 _mvcBuilder = mvcBuilder ;
3943 }
4044
45+ /// <summary>
46+ /// Executes the action provided by the user to configure <see cref="JsonApiOptions"/>
47+ /// </summary>
4148 public void ConfigureJsonApiOptions ( Action < JsonApiOptions > configureOptions ) => configureOptions ( JsonApiOptions ) ;
4249
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>
4356 public void ConfigureMvc ( )
4457 {
4558 RegisterJsonApiStartupServices ( ) ;
@@ -63,16 +76,27 @@ public void ConfigureMvc()
6376 _services . AddSingleton ( routingConvention ) ; // <--- why is this needed?
6477 }
6578
79+ /// <summary>
80+ /// Executes autodiscovery of JADNC services.
81+ /// </summary>
6682 public void AutoDiscover ( Action < IServiceDiscoveryFacade > autoDiscover )
6783 {
6884 autoDiscover ( _serviceDiscoveryFacade ) ;
6985 }
7086
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>
7191 public void ConfigureResources ( Action < IResourceGraphBuilder > resourceGraphBuilder )
7292 {
7393 resourceGraphBuilder ( _resourceGraphBuilder ) ;
7494 }
7595
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>
76100 public void ConfigureResources < TContext > ( Action < IResourceGraphBuilder > resourceGraphBuilder ) where TContext : DbContext
77101 {
78102 _resourceGraphBuilder . AddDbContext < TContext > ( ) ;
@@ -81,17 +105,9 @@ public void ConfigureResources<TContext>(Action<IResourceGraphBuilder> resourceG
81105 resourceGraphBuilder ? . Invoke ( _resourceGraphBuilder ) ;
82106 }
83107
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>
95111 public void ConfigureServices ( )
96112 {
97113 var resourceGraph = _resourceGraphBuilder . Build ( ) ;
@@ -154,7 +170,6 @@ public void ConfigureServices()
154170 _services . AddScoped < IInverseRelationships , InverseRelationships > ( ) ;
155171 }
156172
157-
158173 private void AddQueryParameterServices ( )
159174 {
160175 _services . AddScoped < IIncludeService , IncludeService > ( ) ;
@@ -174,7 +189,6 @@ private void AddQueryParameterServices()
174189 _services . AddScoped < IQueryParameterService > ( sp => sp . GetService < IOmitNullService > ( ) ) ;
175190 }
176191
177-
178192 private void AddResourceHooks ( )
179193 {
180194 _services . AddSingleton ( typeof ( IHooksDiscovery < > ) , typeof ( HooksDiscovery < > ) ) ;
@@ -196,5 +210,16 @@ private void AddServerSerialization()
196210 _services . AddScoped ( sp => sp . GetRequiredService < IJsonApiSerializerFactory > ( ) . GetSerializer ( ) ) ;
197211 _services . AddScoped < IResourceObjectBuilder , ResponseResourceObjectBuilder > ( ) ;
198212 }
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+ }
199224 }
200225}
0 commit comments