开发者

how to inject a logger instance using MEF?

Is it possible to inject an instance of logger class object using Manage开发者_如何学Pythond Extensibility Framework? Please show a sample code snippet.


Yes, using Constructor Injection:

private readonly ILogger logger;

[ImportingConstructor]
public MyClass(ILogger logger)
{
    this.logger = logger;
}

Obviously (if you know MEF) some other type must Export ILogger...

Alternatively, you can also use Property Injection, although I find the semantics vague:

[Import(typeof(ILogger))]
public ILogger Logger { get; set; }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜