Autofac Cannot resolve dependency in module

筅森魡賤 提交于 2019-12-11 04:05:53

问题


I'm new to AutoFac and have what I thought should be a simple scenario.

var builder = new ContainerBuilder();
builder.Register(c => new EventLogLogger()).As<ILogger>();
builder.RegisterModule(new ConfigurationSettingsReader("autofac"));
builder.Build();

I register my ILogger service and then instruct the container to register modules based on values from my app config. The module being loaded has a dependency on ILogger.

public class LocalActorSystemModule : Module {
    private ILogger m_Logger; // The default logging service registered for the system

    public LocalActorSystemModule(ILogger logger) { // 
        m_Logger = logger;
    }

However every time I run the application I get an Autofac.Core.DependencyResolutionException saying that None of the constructors found on type LocalActorSystemModule can be invoked with the available services and parameters. Cannot resolve parameter ILogger. I've tried with RegisterType and RegisterInstance as well.

来源:https://stackoverflow.com/questions/23413211/autofac-cannot-resolve-dependency-in-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!