3

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.

Jesse Carter
  • 20,062
  • 7
  • 64
  • 101
  • Is LocalActorSystemModule an Autofac Module? Are you trying to inject dependencies into it? I don't think you can do that. – Jim Bolla May 02 '14 at 14:44
  • @JimBolla is right - if it is an Autofac module, it's only available to use stuff for building the container; you can't resolve stuff from a container that isn't built. You may need to show us how you're using `LocalActorSystemModule` - where is it registered, and how is it resolved/consumed? – Travis Illig May 02 '14 at 16:19
  • Is this a duplicate question with http://stackoverflow.com/questions/23409559/resolving-autofac-dependencies-inside-module-class ? – Travis Illig May 02 '14 at 16:22

0 Answers0