我在解决方案中有许多使用位框架的项目。当我在不同的项目中使用许多上下文时,我只有最后一个模块的最后一个存储库。
public IEnumerable<IAppModule> GetAppModules()
{
yield return this;
yield return new ModuleA();
yield return new ModuleB();
...
}
public virtual void ConfigureDependencies(IServiceCollection services,IDependencyManager dependencyManager)
{
AssemblyContainer.Current.AddAppAssemblies(typeof(ModuleA).GetTypeInfo().Assembly);
AssemblyContainer.Current.AddAppAssemblies(typeof(ModuleB).GetTypeInfo().Assembly);
...
}
在ModuleA AppModule中:
dependencyManager.RegisterEfCoreDbContext<ModuleAContext, SqlServerDbContextObjectsProvider>();
在ModuleB AppModule中:
dependencyManager.RegisterEfCoreDbContext<ModuleBContext, SqlServerDbContextObjectsProvider>();