Skip to content

Does SimpleNLogModule exist? #26

@FixRM

Description

@FixRM

Hello and thank you for this tool. I have a problem with resolving ILogger with IServiceProvider. My implementation is pretty simple:

    public class ServiceProvider : IServiceProvider
    {
        private readonly ILifetimeScope scope;

        public ServiceProvider(ILifetimeScope scope)
        {
            this.scope = scope;
        }

        public object GetService(Type serviceType)
        {
            return scope.Resolve(serviceType);
        }
    }

and this is registration part:

var builder = new ContainerBuilder();
builder.RegisterModule<NLogModule>();
builder.RegisterType<ServiceProvider>().As<IServiceProvider>();

Types registered with RegisterType are resolved well, but when I try to resolve ILogger I got "The requested service 'NLog.ILogger' has not been registered" exception. If ILogger is injected as constructor parameter then is resolved well as part of ASP.NET DI. What am I doing wrong?

Your Readme says that there is SimpleNLogModule that "is useful when ILogger resolved from Service Locator". But it looks like it doesn't exist any more.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions