Logging in ASP.NET
Hello, ASP.NET automatically creates ILogger<T> through the constructor, but how to create a logger for internal class, like here ?
15 Replies
for FlightRepository in this case
stop creating instances of your classes and let the DI system handle that for you.
+1 to injecting your contexts and repositories
But you could use a ilogger factory
This service would be registered in the DI container, that means it injects dependencies for you, as long as they are also registered.
You wouldn't create your own DB Context in each class, you would constructor inject it as needed just like the ILogger. The same is true for your flight repository. Don't create it yourself. Inject it in the constructor and the DI container will take care of the dependencies
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
I don't use EFCore, my db_context is a regular connection to the postgre db and it's used for each repository
I injected IConfiguration inside my service controller to pull connection string out from there
I guess it's better to add IConfiguration in DbContext and let DI system to handle that
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
did you mean like:
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
I got it
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
tbh, I don't use this class at all 🙂
i should get rid of it
Where it has to be then ?
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
Ok, thanks