@@ -55,9 +55,7 @@ public static class EntityFrameworkServiceCollectionExtensions
55
55
/// </param>
56
56
/// <param name="contextLifetime"> The lifetime with which to register the DbContext service in the container. </param>
57
57
/// <param name="optionsLifetime"> The lifetime with which to register the DbContextOptions service in the container. </param>
58
- /// <returns>
59
- /// The same service collection so that multiple calls can be chained.
60
- /// </returns>
58
+ /// <returns> The same service collection so that multiple calls can be chained. </returns>
61
59
public static IServiceCollection AddDbContext < TContext > (
62
60
this IServiceCollection serviceCollection ,
63
61
Action < DbContextOptionsBuilder > ? optionsAction = null ,
@@ -102,9 +100,7 @@ public static IServiceCollection AddDbContext<TContext>(
102
100
/// </param>
103
101
/// <param name="contextLifetime"> The lifetime with which to register the DbContext service in the container. </param>
104
102
/// <param name="optionsLifetime"> The lifetime with which to register the DbContextOptions service in the container. </param>
105
- /// <returns>
106
- /// The same service collection so that multiple calls can be chained.
107
- /// </returns>
103
+ /// <returns> The same service collection so that multiple calls can be chained. </returns>
108
104
public static IServiceCollection AddDbContext < TContextService , TContextImplementation > (
109
105
this IServiceCollection serviceCollection ,
110
106
Action < DbContextOptionsBuilder > ? optionsAction = null ,
@@ -149,16 +145,12 @@ public static IServiceCollection AddDbContext<TContextService, TContextImplement
149
145
/// will not be called.
150
146
/// </para>
151
147
/// </param>
152
- /// <param name="poolSize">
153
- /// Sets the maximum number of instances retained by the pool.
154
- /// </param>
155
- /// <returns>
156
- /// The same service collection so that multiple calls can be chained.
157
- /// </returns>
148
+ /// <param name="poolSize"> Sets the maximum number of instances retained by the pool. Defaults to 128. </param>
149
+ /// <returns> The same service collection so that multiple calls can be chained. </returns>
158
150
public static IServiceCollection AddDbContextPool < TContext > (
159
151
this IServiceCollection serviceCollection ,
160
152
Action < DbContextOptionsBuilder > optionsAction ,
161
- int poolSize = 128 )
153
+ int poolSize = DbContextPool < DbContext > . DefaultPoolSize )
162
154
where TContext : DbContext
163
155
=> AddDbContextPool < TContext , TContext > ( serviceCollection , optionsAction , poolSize ) ;
164
156
@@ -195,16 +187,12 @@ public static IServiceCollection AddDbContextPool<TContext>(
195
187
/// will not be called.
196
188
/// </para>
197
189
/// </param>
198
- /// <param name="poolSize">
199
- /// Sets the maximum number of instances retained by the pool.
200
- /// </param>
201
- /// <returns>
202
- /// The same service collection so that multiple calls can be chained.
203
- /// </returns>
190
+ /// <param name="poolSize"> Sets the maximum number of instances retained by the pool. Defaults to 128. </param>
191
+ /// <returns> The same service collection so that multiple calls can be chained. </returns>
204
192
public static IServiceCollection AddDbContextPool < TContextService , TContextImplementation > (
205
193
this IServiceCollection serviceCollection ,
206
194
Action < DbContextOptionsBuilder > optionsAction ,
207
- int poolSize = 128 )
195
+ int poolSize = DbContextPool < DbContext > . DefaultPoolSize )
208
196
where TContextImplementation : DbContext , TContextService
209
197
where TContextService : class
210
198
{
@@ -253,16 +241,12 @@ public static IServiceCollection AddDbContextPool<TContextService, TContextImple
253
241
/// will not be called.
254
242
/// </para>
255
243
/// </param>
256
- /// <param name="poolSize">
257
- /// Sets the maximum number of instances retained by the pool.
258
- /// </param>
259
- /// <returns>
260
- /// The same service collection so that multiple calls can be chained.
261
- /// </returns>
244
+ /// <param name="poolSize"> Sets the maximum number of instances retained by the pool. Defaults to 128. </param>
245
+ /// <returns> The same service collection so that multiple calls can be chained. </returns>
262
246
public static IServiceCollection AddDbContextPool < TContext > (
263
247
this IServiceCollection serviceCollection ,
264
248
Action < IServiceProvider , DbContextOptionsBuilder > optionsAction ,
265
- int poolSize = 128 )
249
+ int poolSize = DbContextPool < DbContext > . DefaultPoolSize )
266
250
where TContext : DbContext
267
251
=> AddDbContextPool < TContext , TContext > ( serviceCollection , optionsAction , poolSize ) ;
268
252
@@ -308,16 +292,12 @@ public static IServiceCollection AddDbContextPool<TContext>(
308
292
/// will not be called.
309
293
/// </para>
310
294
/// </param>
311
- /// <param name="poolSize">
312
- /// Sets the maximum number of instances retained by the pool.
313
- /// </param>
314
- /// <returns>
315
- /// The same service collection so that multiple calls can be chained.
316
- /// </returns>
295
+ /// <param name="poolSize"> Sets the maximum number of instances retained by the pool. Defaults to 128. </param>
296
+ /// <returns> The same service collection so that multiple calls can be chained. </returns>
317
297
public static IServiceCollection AddDbContextPool < TContextService , TContextImplementation > (
318
298
this IServiceCollection serviceCollection ,
319
299
Action < IServiceProvider , DbContextOptionsBuilder > optionsAction ,
320
- int poolSize = 128 )
300
+ int poolSize = DbContextPool < DbContext > . DefaultPoolSize )
321
301
where TContextImplementation : DbContext , TContextService
322
302
where TContextService : class
323
303
{
@@ -381,9 +361,7 @@ private static void AddPoolingOptions<TContext>(
381
361
/// <param name="serviceCollection"> The <see cref="IServiceCollection" /> to add services to. </param>
382
362
/// <param name="contextLifetime"> The lifetime with which to register the DbContext service in the container. </param>
383
363
/// <param name="optionsLifetime"> The lifetime with which to register the DbContextOptions service in the container. </param>
384
- /// <returns>
385
- /// The same service collection so that multiple calls can be chained.
386
- /// </returns>
364
+ /// <returns> The same service collection so that multiple calls can be chained. </returns>
387
365
public static IServiceCollection AddDbContext < TContext > (
388
366
this IServiceCollection serviceCollection ,
389
367
ServiceLifetime contextLifetime ,
@@ -411,9 +389,7 @@ public static IServiceCollection AddDbContext<TContext>(
411
389
/// <param name="serviceCollection"> The <see cref="IServiceCollection" /> to add services to. </param>
412
390
/// <param name="contextLifetime"> The lifetime with which to register the DbContext service in the container. </param>
413
391
/// <param name="optionsLifetime"> The lifetime with which to register the DbContextOptions service in the container. </param>
414
- /// <returns>
415
- /// The same service collection so that multiple calls can be chained.
416
- /// </returns>
392
+ /// <returns> The same service collection so that multiple calls can be chained. </returns>
417
393
public static IServiceCollection AddDbContext < TContextService , TContextImplementation > (
418
394
this IServiceCollection serviceCollection ,
419
395
ServiceLifetime contextLifetime ,
@@ -470,9 +446,7 @@ public static IServiceCollection AddDbContext<TContextService, TContextImplement
470
446
/// </param>
471
447
/// <param name="contextLifetime"> The lifetime with which to register the DbContext service in the container. </param>
472
448
/// <param name="optionsLifetime"> The lifetime with which to register the DbContextOptions service in the container. </param>
473
- /// <returns>
474
- /// The same service collection so that multiple calls can be chained.
475
- /// </returns>
449
+ /// <returns> The same service collection so that multiple calls can be chained. </returns>
476
450
public static IServiceCollection AddDbContext < TContext > (
477
451
this IServiceCollection serviceCollection ,
478
452
Action < IServiceProvider , DbContextOptionsBuilder > ? optionsAction ,
@@ -527,9 +501,7 @@ public static IServiceCollection AddDbContext<TContext>(
527
501
/// </param>
528
502
/// <param name="contextLifetime"> The lifetime with which to register the DbContext service in the container. </param>
529
503
/// <param name="optionsLifetime"> The lifetime with which to register the DbContextOptions service in the container. </param>
530
- /// <returns>
531
- /// The same service collection so that multiple calls can be chained.
532
- /// </returns>
504
+ /// <returns> The same service collection so that multiple calls can be chained. </returns>
533
505
public static IServiceCollection AddDbContext < TContextService , TContextImplementation > (
534
506
this IServiceCollection serviceCollection ,
535
507
Action < IServiceProvider , DbContextOptionsBuilder > ? optionsAction ,
@@ -600,9 +572,7 @@ public static IServiceCollection AddDbContext<TContextService, TContextImplement
600
572
/// The lifetime with which to register the factory and options.
601
573
/// The default is <see cref="ServiceLifetime.Singleton" />
602
574
/// </param>
603
- /// <returns>
604
- /// The same service collection so that multiple calls can be chained.
605
- /// </returns>
575
+ /// <returns> The same service collection so that multiple calls can be chained. </returns>
606
576
public static IServiceCollection AddDbContextFactory < TContext > (
607
577
this IServiceCollection serviceCollection ,
608
578
Action < DbContextOptionsBuilder > ? optionsAction = null ,
@@ -659,9 +629,7 @@ public static IServiceCollection AddDbContextFactory<TContext>(
659
629
/// The lifetime with which to register the factory and options.
660
630
/// The default is <see cref="ServiceLifetime.Singleton" />
661
631
/// </param>
662
- /// <returns>
663
- /// The same service collection so that multiple calls can be chained.
664
- /// </returns>
632
+ /// <returns> The same service collection so that multiple calls can be chained. </returns>
665
633
public static IServiceCollection AddDbContextFactory < TContext , TFactory > (
666
634
this IServiceCollection serviceCollection ,
667
635
Action < DbContextOptionsBuilder > ? optionsAction = null ,
@@ -727,9 +695,7 @@ public static IServiceCollection AddDbContextFactory<TContext, TFactory>(
727
695
/// The lifetime with which to register the factory and options.
728
696
/// The default is <see cref="ServiceLifetime.Singleton" />
729
697
/// </param>
730
- /// <returns>
731
- /// The same service collection so that multiple calls can be chained.
732
- /// </returns>
698
+ /// <returns> The same service collection so that multiple calls can be chained. </returns>
733
699
public static IServiceCollection AddDbContextFactory < TContext > (
734
700
this IServiceCollection serviceCollection ,
735
701
Action < IServiceProvider , DbContextOptionsBuilder > optionsAction ,
@@ -794,9 +760,7 @@ public static IServiceCollection AddDbContextFactory<TContext>(
794
760
/// The lifetime with which to register the factory and options.
795
761
/// The default is <see cref="ServiceLifetime.Singleton" />
796
762
/// </param>
797
- /// <returns>
798
- /// The same service collection so that multiple calls can be chained.
799
- /// </returns>
763
+ /// <returns> The same service collection so that multiple calls can be chained. </returns>
800
764
public static IServiceCollection AddDbContextFactory < TContext , TFactory > (
801
765
this IServiceCollection serviceCollection ,
802
766
Action < IServiceProvider , DbContextOptionsBuilder > ? optionsAction ,
@@ -850,16 +814,12 @@ public static IServiceCollection AddDbContextFactory<TContext, TFactory>(
850
814
/// will not be called.
851
815
/// </para>
852
816
/// </param>
853
- /// <param name="poolSize">
854
- /// Sets the maximum number of instances retained by the pool.
855
- /// </param>
856
- /// <returns>
857
- /// The same service collection so that multiple calls can be chained.
858
- /// </returns>
817
+ /// <param name="poolSize"> Sets the maximum number of instances retained by the pool. Defaults to 128. </param>
818
+ /// <returns> The same service collection so that multiple calls can be chained. </returns>
859
819
public static IServiceCollection AddPooledDbContextFactory < TContext > (
860
820
this IServiceCollection serviceCollection ,
861
821
Action < DbContextOptionsBuilder > optionsAction ,
862
- int poolSize = 128 )
822
+ int poolSize = DbContextPool < DbContext > . DefaultPoolSize )
863
823
where TContext : DbContext
864
824
{
865
825
Check . NotNull ( optionsAction , nameof ( optionsAction ) ) ;
@@ -898,16 +858,12 @@ public static IServiceCollection AddPooledDbContextFactory<TContext>(
898
858
/// will not be called.
899
859
/// </para>
900
860
/// </param>
901
- /// <param name="poolSize">
902
- /// Sets the maximum number of instances retained by the pool.
903
- /// </param>
904
- /// <returns>
905
- /// The same service collection so that multiple calls can be chained.
906
- /// </returns>
861
+ /// <param name="poolSize"> Sets the maximum number of instances retained by the pool. Defaults to 128. </param>
862
+ /// <returns> The same service collection so that multiple calls can be chained. </returns>
907
863
public static IServiceCollection AddPooledDbContextFactory < TContext > (
908
864
this IServiceCollection serviceCollection ,
909
865
Action < IServiceProvider , DbContextOptionsBuilder > optionsAction ,
910
- int poolSize = 128 )
866
+ int poolSize = DbContextPool < DbContext > . DefaultPoolSize )
911
867
where TContext : DbContext
912
868
{
913
869
Check . NotNull ( serviceCollection , nameof ( serviceCollection ) ) ;
@@ -916,7 +872,8 @@ public static IServiceCollection AddPooledDbContextFactory<TContext>(
916
872
AddPoolingOptions < TContext > ( serviceCollection , optionsAction , poolSize ) ;
917
873
918
874
serviceCollection . TryAddSingleton < IDbContextPool < TContext > , DbContextPool < TContext > > ( ) ;
919
- serviceCollection . TryAddSingleton < IDbContextFactory < TContext > , PooledDbContextFactory < TContext > > ( ) ;
875
+ serviceCollection . TryAddSingleton < IDbContextFactory < TContext > > (
876
+ sp => new PooledDbContextFactory < TContext > ( sp . GetRequiredService < IDbContextPool < TContext > > ( ) ) ) ;
920
877
921
878
return serviceCollection ;
922
879
}
0 commit comments