Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to inject ILogger<T> #49

Closed
kapilbhavsar opened this issue Apr 8, 2021 · 1 comment
Closed

How to inject ILogger<T> #49

kapilbhavsar opened this issue Apr 8, 2021 · 1 comment

Comments

@kapilbhavsar
Copy link

kapilbhavsar commented Apr 8, 2021

How can I inject type ILogger<MyService> in MyService class

@merken
Copy link
Owner

merken commented Apr 8, 2021

Hi,

I assume you're talking about injecting ILogger into a plugin or a service inside a plugin ?
I would advise not to use ILogger, but to provide an abstraction that is defined in your Contract

Something like:

public interface IPluginLogger
{
void LogInformation(string message);
void LogError(string message);
}

In the Host you must provide the implementation like an Adapter pattern, meaning you wrap the ILogger inside the IPluginLogger (or MyPluginLogger)

Just remember to use ILogger instead of ILogger, you will lose some metadata, but this way, backwards compatibility is guaranteed.

There's an example of this in the docs at Host Services https://merken.github.io/Prise/#/?id=🎩-host-services

@merken merken closed this as completed Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants