解决Module类中的AutoFac依赖关系

杰西·卡特(Jesse Carter)

我是AutoFac的新手,目前正在我的应用程序配置中使用自定义模块来启动一些核心F#系统。我正在使用的代码是

var builder = new ContainerBuilder();
builder.RegisterType<DefaultLogger>().As<IDefaultLogger>();
builder.RegisterModule(new ConfigurationSettingsReader("autofac"));
builder.Build();

在我的应用程序配置中,我具有启动相关系统的适当逻辑。我想访问模块内的DefaultLogger。我可以使用Module基类的元数据以下选项:

protected virtual void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration);

protected virtual void AttachToRegistrationSource(IComponentRegistry componentRegistry, IRegistrationSource registrationSource);

public void Configure(IComponentRegistry componentRegistry);

protected virtual void Load(ContainerBuilder builder);

到目前为止,我仅使用过Load,并且在构建器上看不到任何允许我使用日志记录服务的方法。

杰西·卡特(Jesse Carter)

答案非常简单。我刚刚将IComponentContext添加为模块实现的依赖项

public class LocalActorSystemModule : Module {
    private IComponentContext m_ComponentContext; // A service for resolving dependencies required by this module

    public LocalActorSystemModule(IComponentContext componentContext) { 
        m_ComponentContext = componentContext;
    }

然后让AutoFac为我注入IComponentContext。这样,我可以解决模块内部所需的所有依赖项。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

解决条件依赖关系autofac

Autofac:解决 ApiControllers 的依赖关系

使用Autofac动态解决依赖关系

如何使用Unity解决静态类中的依赖关系?

依赖关系未解决:DocumentBuilderFactory 类需要在 openJDK 11 中依赖 javax.xml.parsers

CQRS CommandDispatcher中的Autofac解决依赖项

如何在Maven工件中运行Java类,自动解决依赖关系?

使用结构并将其视为类来解决Golang中的依赖关系是否不好?

无法在Maven中解决导入/依赖关系

Laravel 5解决ServiceProvider中的依赖关系

解决Eclipse for Fitnesse中的依赖关系

解决Terraform中的资源依赖关系

使用autofac解决或注入global.asax中的依赖项

依赖关系未解决

阴谋解决依赖关系

在Roslyn中获取类之间的依赖关系

如何添加具有需要由Autofac解决的依赖关系的自定义ModelMetadataDetailsProvider?

CMake中的LibSodium依赖关系在Docker容器中无法解决

解决python / django应用程序中的循环依赖关系

使用serviceKey解决DryIoc中的子依赖关系失败

Unity-使用请求中的信息来解决依赖关系

Android:无法解决Android Studio中的依赖关系

无法从BOM表文件中解决依赖关系

在Spring Tool Suite中无法解决Spring依赖关系

如何解决Go中的软件包依赖关系?

无法解决12.04中libpango-1.0-0的依赖关系

在Spring中手动解决依赖关系[启动]

错误:无法解决Android Studio 3.4中的依赖关系

Gradle无法解决IntelliJ中的Sonatype Nexus依赖关系