@@ -55,9 +55,7 @@ public static class EntityFrameworkServiceCollectionExtensions
5555 /// </param>
5656 /// <param name="contextLifetime"> The lifetime with which to register the DbContext service in the container. </param>
5757 /// <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>
6159 public static IServiceCollection AddDbContext < TContext > (
6260 this IServiceCollection serviceCollection ,
6361 Action < DbContextOptionsBuilder > ? optionsAction = null ,
@@ -102,9 +100,7 @@ public static IServiceCollection AddDbContext<TContext>(
102100 /// </param>
103101 /// <param name="contextLifetime"> The lifetime with which to register the DbContext service in the container. </param>
104102 /// <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>
108104 public static IServiceCollection AddDbContext < TContextService , TContextImplementation > (
109105 this IServiceCollection serviceCollection ,
110106 Action < DbContextOptionsBuilder > ? optionsAction = null ,
@@ -149,16 +145,12 @@ public static IServiceCollection AddDbContext<TContextService, TContextImplement
149145 /// will not be called.
150146 /// </para>
151147 /// </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>
158150 public static IServiceCollection AddDbContextPool < TContext > (
159151 this IServiceCollection serviceCollection ,
160152 Action < DbContextOptionsBuilder > optionsAction ,
161- int poolSize = 128 )
153+ int poolSize = DbContextPool < DbContext > . DefaultPoolSize )
162154 where TContext : DbContext
163155 => AddDbContextPool < TContext , TContext > ( serviceCollection , optionsAction , poolSize ) ;
164156
@@ -195,16 +187,12 @@ public static IServiceCollection AddDbContextPool<TContext>(
195187 /// will not be called.
196188 /// </para>
197189 /// </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>
204192 public static IServiceCollection AddDbContextPool < TContextService , TContextImplementation > (
205193 this IServiceCollection serviceCollection ,
206194 Action < DbContextOptionsBuilder > optionsAction ,
207- int poolSize = 128 )
195+ int poolSize = DbContextPool < DbContext > . DefaultPoolSize )
208196 where TContextImplementation : DbContext , TContextService
209197 where TContextService : class
210198 {
@@ -253,16 +241,12 @@ public static IServiceCollection AddDbContextPool<TContextService, TContextImple
253241 /// will not be called.
254242 /// </para>
255243 /// </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>
262246 public static IServiceCollection AddDbContextPool < TContext > (
263247 this IServiceCollection serviceCollection ,
264248 Action < IServiceProvider , DbContextOptionsBuilder > optionsAction ,
265- int poolSize = 128 )
249+ int poolSize = DbContextPool < DbContext > . DefaultPoolSize )
266250 where TContext : DbContext
267251 => AddDbContextPool < TContext , TContext > ( serviceCollection , optionsAction , poolSize ) ;
268252
@@ -308,16 +292,12 @@ public static IServiceCollection AddDbContextPool<TContext>(
308292 /// will not be called.
309293 /// </para>
310294 /// </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>
317297 public static IServiceCollection AddDbContextPool < TContextService , TContextImplementation > (
318298 this IServiceCollection serviceCollection ,
319299 Action < IServiceProvider , DbContextOptionsBuilder > optionsAction ,
320- int poolSize = 128 )
300+ int poolSize = DbContextPool < DbContext > . DefaultPoolSize )
321301 where TContextImplementation : DbContext , TContextService
322302 where TContextService : class
323303 {
@@ -381,9 +361,7 @@ private static void AddPoolingOptions<TContext>(
381361 /// <param name="serviceCollection"> The <see cref="IServiceCollection" /> to add services to. </param>
382362 /// <param name="contextLifetime"> The lifetime with which to register the DbContext service in the container. </param>
383363 /// <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>
387365 public static IServiceCollection AddDbContext < TContext > (
388366 this IServiceCollection serviceCollection ,
389367 ServiceLifetime contextLifetime ,
@@ -411,9 +389,7 @@ public static IServiceCollection AddDbContext<TContext>(
411389 /// <param name="serviceCollection"> The <see cref="IServiceCollection" /> to add services to. </param>
412390 /// <param name="contextLifetime"> The lifetime with which to register the DbContext service in the container. </param>
413391 /// <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>
417393 public static IServiceCollection AddDbContext < TContextService , TContextImplementation > (
418394 this IServiceCollection serviceCollection ,
419395 ServiceLifetime contextLifetime ,
@@ -470,9 +446,7 @@ public static IServiceCollection AddDbContext<TContextService, TContextImplement
470446 /// </param>
471447 /// <param name="contextLifetime"> The lifetime with which to register the DbContext service in the container. </param>
472448 /// <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>
476450 public static IServiceCollection AddDbContext < TContext > (
477451 this IServiceCollection serviceCollection ,
478452 Action < IServiceProvider , DbContextOptionsBuilder > ? optionsAction ,
@@ -527,9 +501,7 @@ public static IServiceCollection AddDbContext<TContext>(
527501 /// </param>
528502 /// <param name="contextLifetime"> The lifetime with which to register the DbContext service in the container. </param>
529503 /// <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>
533505 public static IServiceCollection AddDbContext < TContextService , TContextImplementation > (
534506 this IServiceCollection serviceCollection ,
535507 Action < IServiceProvider , DbContextOptionsBuilder > ? optionsAction ,
@@ -600,9 +572,7 @@ public static IServiceCollection AddDbContext<TContextService, TContextImplement
600572 /// The lifetime with which to register the factory and options.
601573 /// The default is <see cref="ServiceLifetime.Singleton" />
602574 /// </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>
606576 public static IServiceCollection AddDbContextFactory < TContext > (
607577 this IServiceCollection serviceCollection ,
608578 Action < DbContextOptionsBuilder > ? optionsAction = null ,
@@ -659,9 +629,7 @@ public static IServiceCollection AddDbContextFactory<TContext>(
659629 /// The lifetime with which to register the factory and options.
660630 /// The default is <see cref="ServiceLifetime.Singleton" />
661631 /// </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>
665633 public static IServiceCollection AddDbContextFactory < TContext , TFactory > (
666634 this IServiceCollection serviceCollection ,
667635 Action < DbContextOptionsBuilder > ? optionsAction = null ,
@@ -727,9 +695,7 @@ public static IServiceCollection AddDbContextFactory<TContext, TFactory>(
727695 /// The lifetime with which to register the factory and options.
728696 /// The default is <see cref="ServiceLifetime.Singleton" />
729697 /// </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>
733699 public static IServiceCollection AddDbContextFactory < TContext > (
734700 this IServiceCollection serviceCollection ,
735701 Action < IServiceProvider , DbContextOptionsBuilder > optionsAction ,
@@ -794,9 +760,7 @@ public static IServiceCollection AddDbContextFactory<TContext>(
794760 /// The lifetime with which to register the factory and options.
795761 /// The default is <see cref="ServiceLifetime.Singleton" />
796762 /// </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>
800764 public static IServiceCollection AddDbContextFactory < TContext , TFactory > (
801765 this IServiceCollection serviceCollection ,
802766 Action < IServiceProvider , DbContextOptionsBuilder > ? optionsAction ,
@@ -850,16 +814,12 @@ public static IServiceCollection AddDbContextFactory<TContext, TFactory>(
850814 /// will not be called.
851815 /// </para>
852816 /// </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>
859819 public static IServiceCollection AddPooledDbContextFactory < TContext > (
860820 this IServiceCollection serviceCollection ,
861821 Action < DbContextOptionsBuilder > optionsAction ,
862- int poolSize = 128 )
822+ int poolSize = DbContextPool < DbContext > . DefaultPoolSize )
863823 where TContext : DbContext
864824 {
865825 Check . NotNull ( optionsAction , nameof ( optionsAction ) ) ;
@@ -898,16 +858,12 @@ public static IServiceCollection AddPooledDbContextFactory<TContext>(
898858 /// will not be called.
899859 /// </para>
900860 /// </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>
907863 public static IServiceCollection AddPooledDbContextFactory < TContext > (
908864 this IServiceCollection serviceCollection ,
909865 Action < IServiceProvider , DbContextOptionsBuilder > optionsAction ,
910- int poolSize = 128 )
866+ int poolSize = DbContextPool < DbContext > . DefaultPoolSize )
911867 where TContext : DbContext
912868 {
913869 Check . NotNull ( serviceCollection , nameof ( serviceCollection ) ) ;
@@ -916,7 +872,8 @@ public static IServiceCollection AddPooledDbContextFactory<TContext>(
916872 AddPoolingOptions < TContext > ( serviceCollection , optionsAction , poolSize ) ;
917873
918874 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 > > ( ) ) ) ;
920877
921878 return serviceCollection ;
922879 }
0 commit comments