Chr*_*nes 8 dependency-injection castle-windsor property-injection
我的课程中有一个属性用于记录服务.
private ILogger logger = NullLogger.Instance;
public ILogger Logger
{
get { return logger; }
set { logger = value; }
}
Run Code Online (Sandbox Code Playgroud)
我在组件注册中有这个:
container.AddFacility<LoggingFacility>(x => new LoggingFacility(LoggerImplementation.Log4net));
Run Code Online (Sandbox Code Playgroud)
然而,温莎似乎没有注入记录器 - 我错过了什么?
Mau*_*fer 14
AddFacility的lambda参数实际上是一个创建回调(它在创建工具时调用),而不是工厂.
请改用:
container.AddFacility("logging", new LoggingFacility(LoggerImplementation.Log4net, "path_to_log4net.config"));
Run Code Online (Sandbox Code Playgroud)
BTW Windsor会在可能的情况下自动注入属性依赖项.