开发者

how to inject a logger instance using MEF?

开发者 https://www.devze.com 2022-12-22 23:36 出处:网络
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:

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

精彩评论

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