Skip to content

How to use with DI? #166

Answered by pamidur
pamidur asked this question in Q&A
Oct 18, 2021 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

This is not a final solution for DI problem, we still work on it, but
let's see what options we have:

Option 1: Create and manage logger inside aspect:

This is quite easy provided you use global aspects. Global aspects are singletons by themselves. So everything you create in their constructor are singletons as well.

    [Aspect(Scope.Global)]
    public class LogAspect : Attribute
    {
        private readonly TelemetryClient_logger;

        public LogAspect(ILogger logger)
        {
            _logger = new TelemetryClient();
        }
...

You can still use Scope.PerInstance but then make sure you manage your instance TelemetryClient properly (e.g. create one in static constructor of…

Replies: 2 comments 1 reply

Comment options

pamidur
Oct 18, 2021
Maintainer Author

You must be logged in to vote
0 replies
Answer selected by pamidur
Comment options

You must be logged in to vote
1 reply
@pamidur
Comment options

pamidur Apr 26, 2022
Maintainer Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants