Entityframework.docs: Is your example doing what it comments not to do?

Created on 8 Sep 2020  Â·  1Comment  Â·  Source: dotnet/EntityFramework.Docs

You state in your comment
.UseLoggerFactory(MyLoggerFactory) // Warning: Do not create a new ILoggerFactory instance each time

Are you giving an example of what not to do? or is your example usable as is?

LoggerFactory.Create should return a singleton, no?


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

closed-question

Most helpful comment

Example usable as is. If you see definition of MyLoggerFactory then it is a static field which is initialized only once per class so everytime you initialize the context, it would be same logger factory. The comment specifically says that do not create new instance and pass here every time which using a static field solves.

LoggerFactory.Create should return a singleton, no?

Singleton/scoped is inside DI. This is outside of DI. Create method creates a logger factory and gives it back to user. There is no scoping. User needs to manage object themselves.

>All comments

Example usable as is. If you see definition of MyLoggerFactory then it is a static field which is initialized only once per class so everytime you initialize the context, it would be same logger factory. The comment specifically says that do not create new instance and pass here every time which using a static field solves.

LoggerFactory.Create should return a singleton, no?

Singleton/scoped is inside DI. This is outside of DI. Create method creates a logger factory and gives it back to user. There is no scoping. User needs to manage object themselves.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MohammadMQ picture MohammadMQ  Â·  3Comments

davidliang2008 picture davidliang2008  Â·  4Comments

weitzhandler picture weitzhandler  Â·  4Comments

jpeckham picture jpeckham  Â·  3Comments

ajcvickers picture ajcvickers  Â·  4Comments