public static IServiceCollection AddTenantContext <TContext, TProvider>(this IServiceCollection services, Action <RepositoryOptions> options = null) where TContext : CoreContext where TProvider : class, ITenantProvider { var repositoryOptions = new RepositoryOptions(); options?.Invoke(repositoryOptions); services.AddDbContext <TContext>(repositoryOptions.Builder()); services.AddScoped <TContext>(); services.AddScoped <IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped <ITenantProvider, TProvider>(); return(services); }
public static IServiceCollection AddContext <TContext>(this IServiceCollection services, Action <RepositoryOptions> options = null) where TContext : CoreContext { var repositoryOptions = new RepositoryOptions(); options?.Invoke(repositoryOptions); services.AddDbContext <TContext>(repositoryOptions.Builder()); services.AddScoped <CoreContext, TContext>(); services.AddScoped <IUnitOfWork, UnitOfWork>(); services.AddScoped(typeof(IRepository <,>), typeof(Repository <,>)); services.AddScoped(typeof(IReadRepository <,>), typeof(Repository <,>)); services.AddScoped(typeof(IWriteRepository <,>), typeof(Repository <,>)); return(services); }
/// <summary> /// 添加仓储配置 /// </summary> /// <typeparam name="TContext"></typeparam> /// <param name="server"><see cref="RepositoryBuilder"/></param> /// <param name="storeOptionsAction">仓储配置设置函数</param> /// <returns></returns> public static RepositoryBuilder AddIdentityRepository(this RepositoryBuilder builder, RepositoryOptions options) { builder.Service.AddScoped <RepositoryDbContext>(); //builder.Service.AddDbContext<RepositoryDbContext>(options.DbContextOptions); //添加仓储服务 builder.AddRepository <ClientRepository, Client>(); builder.AddRepository <ApiResourceRepository, ApiResource>(); builder.AddRepository <IdentityResourceRepository, IdentityResource>(); builder.AddRepository <PersistedGrantRepository, PersistedGrant>(); builder.AddRepository <IdentityTokenRepository, IdentityToken>(); //添加数据商店服务 builder.Service.AddTransient <IApiResourceRepositories, ApiResourceRepository>(); builder.Service.AddTransient <IClientRepositories, ClientRepository>(); builder.Service.AddTransient <IIdentityResourceRepositories, IdentityResourceRepository>(); builder.Service.AddTransient <IPersistedGrantRepositories, PersistedGrantRepository>(); return(builder); }