Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

abp 模块化 #1

Open
xkissboss opened this issue Feb 17, 2020 · 3 comments
Open

abp 模块化 #1

xkissboss opened this issue Feb 17, 2020 · 3 comments

Comments

@xkissboss
Copy link

abp模块化使用插件式开发,如何使用各自的db

@zhenl
Copy link
Owner

zhenl commented Feb 17, 2020

不同的模块可以有不同的DbContext,连接不同的数据库字符串,比如某个项目有两个模块,相应的DbContext分别为MyFlowDbContext和MyPlatDbContext,这两个DbContext可以分别定义不同的连接字符串:
public class MyPlatDbContext : AbpZeroDbContext<Tenant, Role, User>
{
......
public MyPlatDbContext()
: base("DefaultPlat")
{

    }
}

......
public class MyFlowDbContext:AbpDbContext
{
......
public MyFlowDbContext()
: base("name=DefaultFlow")
{

    }

}

@xkissboss
Copy link
Author

MyPlatDbContext和MyFlowDbContext存在相同的表
那么使用IRepository注入的时怎么动态制定获取的DbContext
或者留个微信,有空私聊

@zhenl
Copy link
Owner

zhenl commented Feb 19, 2020

两个模块之间是独立的,每个模块中各个部分的依赖关系已经设定,因此,不会出现冲突,比如:
IRepository<ProcessInstancePermission, int>,这里ProcessInstancePermission在MyFlowCoreModule中定义,MyFlowDataModule 依赖于MyFlowCoreModule,使用MyFlowDbContext,示例代码如下:

[DependsOn(
//typeof(AbpZeroEntityFrameworkModule), typeof(MyPlatCoreModule),
typeof(MyFlowCoreModule),
typeof(AbpEntityFrameworkModule))]
public class MyFlowDataModule : AbpModule
{
public override void PreInitialize()
{
Database.SetInitializer(new CreateDatabaseIfNotExists());
Database.SetInitializer(null);
Configuration.DefaultNameOrConnectionString = "Default";
}

    public override void Initialize()
    {
        IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
        IocManager.IocContainer.Register(
             Component.For<ISqlQuery<ProcessInstanceStatus>>().ImplementedBy<SqlQuery<ProcessInstanceStatus>>().LifestyleTransient()
);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants