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

Get typeof parent in factory #117

Closed
trampster opened this issue Jun 3, 2021 · 3 comments
Closed

Get typeof parent in factory #117

trampster opened this issue Jun 3, 2021 · 3 comments

Comments

@trampster
Copy link

trampster commented Jun 3, 2021

We use serilog for logging and it needs to be initialised with the type of the object it will be logging for (the type it is injected into)

ILogger specificLogger = logger.ForContext(typeof(Parent))

Our types have the ILogger as constructor arguments and out current injection framework creates them for us with the correct context.

I can't see anyway to achieve this with stronginject Factories

@YairHalberstadt
Copy link
Owner

Currently stronginject have no knowledge of why they're being resolved. I would like to provide a solution to this, but it is not a priority at the moment.

In the meantime, I would suggest using Microsoft.Extensions.Logging.ILogger. Their logger takes a type parameter to mark the type it's used for, which allows easy resolution. I'm sure there is an implementation of this interface for Serilog.

I know changing everything may not be practical. I will try to think of a way to intercept a resolution and inject some extra information.

@YairHalberstadt
Copy link
Owner

I have proposed a design at #109 (comment). Please take a look and let me know what you think! Thanks!

@YairHalberstadt
Copy link
Owner

CLosing as duplicate of #109

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