Explicit resolving of ILog in Autofac when using with Log Injection Module

前端 未结 3 2341
一向
一向 2021-01-01 04:15

I use the following code in order to register log4net for all the classes that need it.

public class LogInjectionModule : Module
{
    private readonly strin         


        
3条回答
  •  庸人自扰
    2021-01-01 04:45

    The builder needs to Build a container before it can Resolve.

    Try something like this (untested)

    builder
        .RegisterAssemblyTypes(typeof (IResourceFinder).Assembly)
        .AsImplementedInterfaces();
    /* process LogInjectionModule */
    IContainer container = builder.Build();
    
    var updateBuilder = new ContainerBuilder();
    updateBuilder
        .Register(x => new ClassThatNeedsILog(x.Resolve()))
        .AsImplementedInterfaces();
    updateBuilder.Update(container);
    

提交回复
热议问题