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?
Introduction. Dependency Injection (DI) is an established design pattern describing how objects acquire their dependencies. This pattern is often facilitated by an Inversion of Control (IoC) container, which is used at runtime. to resolve and inject dependencies as objects are instantiated.
Property injection is a type of dependency injection where dependencies are provided through properties. Visit the Dependency Injection chapter to learn more about it. Let's understand how we can perform property injection using Unity container. Consider the following example classes.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With