如何在比特框架中的不同项目中进行模块化依赖注册?

时间:2017-12-02 15:05:34

标签: c# .net bit bit-framework

我在使用位框架的解决方案中有很多项目。我需要在每个项目中注册接口,并进行模块化注册。怎么办?

1 个答案:

答案 0 :(得分:3)

使用以下模块进行成像:“FrontApp + SubSys1 + SubSys2”

AppStartup与以前一样经过两次修改:

1-在AssemblyContainer.Current.Init();之后添加以下代码:

AssemblyContainer.Current.AddAppAssemblies(typeof(SubSys1AppModule).GetTypeInfo().Assembly, typeof(SubSys2AppModule).GetTypeInfo().Assembly);

2-将GetAppModules的正文更改为以下内容:

public IEnumerable<IAppModule> GetAppModules()
{
    yield return this;
    yield return new SubSys1AppModule();
    yield return new SubSys2AppModule();
}

SubSys1AppModule的代码:

public class SubSys1AppModule : IAspNetCoreAppModule // It's possible in owin based apps by implementing IOwinAppModule
{
    public virtual void ConfigureDependencies(IServiceProvider serviceProvider, IServiceCollection services, IDependencyManager dependencyManager)
    {
        dependencyManager.Register<Module1Contract, Module1Implementation>();
    }
}