src/Extensions/ServiceRepositoryBuilderExtensions.cs
/// <summary>
/// Add Repository DbContext to the DI system.
/// </summary>        
/// <typeparam name="TContext">The IRegistryDbContext to use.</typeparam>
/// <param name="services">The service collection.</param>
/// <param name="storeOptionsAction">The store options action.</param>
/// <returns></returns>
Add Repository DbContext to the DI system.
Add Repository DbContext to the DI system .
public static IServiceCollection AddRepositoryDbContext<TContext>(this IServiceCollection services, Action<RepositoryStoreOptions> storeOptionsAction = null)
            where TContext : DbContext, IRepositoryDbContext
        {
            var options = new RepositoryStoreOptions();
            services.AddSingleton(options);
            storeOptionsAction?.Invoke(options);
            if (options.ResolveDbContextOptions != null)
            {
                services.AddDbContext<TContext>(options.ResolveDbContextOptions);
            }
            else
            {
                services.AddDbContext<TContext>(dbCtxBuilder => options.ConfigureDbContext?.Invoke(dbCtxBuilder));
            }
            services.AddScoped<IRepositoryDbContext, TContext>();
            return services;
        }
public static IServiceCollection AddRepositoryDbContext < TContext > ( this IServiceCollection services , Action < RepositoryStoreOptions > storeOptionsAction = null ) where TContext : DbContext , IRepositoryDbContext { var options = new RepositoryStoreOptions ( ) ; services . AddSingleton ( options ) ; storeOptionsAction ? . Invoke ( options ) ; if ( options . ResolveDbContextOptions != null ) { services . AddDbContext < TContext > ( options . ResolveDbContextOptions ) ; } else { services . AddDbContext < TContext > ( dbCtxBuilder => options . ConfigureDbContext ? . Invoke ( dbCtxBuilder ) ) ; } services . AddScoped < IRepositoryDbContext , TContext > ( ) ; return services ; }
Add Repository DbContext to the DI system.
Add Repository DbContext to the DI system .
None
IServiceCollection
this
storeOptionsAction
Action<RepositoryStoreOptions>
The store options action.
The store options action .
services
The service collection.
The service collection .
typeparam
The IRegistryDbContext to use.
The IRegistryDbContext to use .