Hi,
Is it possible to inject an instance of logger class object using Managed Extensibility Framework. Please show a sample code snippet.
Thanks in advance
Hi,
Is it possible to inject an instance of logger class object using Managed Extensibility Framework. Please show a sample code snippet.
Thanks in advance
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; }