How can I get Castle Windsor to automatically inject a property?
Asked Answered
F

1

8

I have a property on my classes for logging service.

private ILogger logger = NullLogger.Instance;
public ILogger Logger
{
    get { return logger; }
    set { logger = value; }
}

And I have this in my component registration:

container.AddFacility<LoggingFacility>(x => new LoggingFacility(LoggerImplementation.Log4net));

However, Windsor doesn't seem to inject the Logger - am I missing something?

Fash answered 29/6, 2009 at 14:55 Comment(0)
V
14

The lambda parameter for AddFacility is actually a creation callback (it gets called when the facility is created), not a factory.

Use this instead:

container.AddFacility("logging", new LoggingFacility(LoggerImplementation.Log4net, "path_to_log4net.config"));

BTW Windsor automatically injects property dependencies whenever it can.

Vala answered 29/6, 2009 at 23:29 Comment(1)
Thank you, you are starting to become my personal Windsor assistant :-)Fash

© 2022 - 2024 — McMap. All rights reserved.