1

When adding a DbContext to your service container via AddDbContextPool, it appears that you can only use a constructor with a single argument of DbContextOptions<YourDbContextImplementation>.

To get a TelemetryClient in .NET Core 3+, it is NOT recommended (aka deprecated) to instantiate TelemetryClient with 'new'.

Given these two constraints, how can one get a TelemetryClient when you cannot get one via Constructor DI?

A potential use case would be a Metric to track how many DbContext are created.

(I am currently using EF Core 2.4 due to pending updates to handle the breaking client-side evaluation changes in 3)

jeubank12
  • 891
  • 9
  • 17
  • Usually, what is between "<" and ">" is a type parameter, not an instance. The signature of the DbContextOptions Constructor looks like DbContextOptions(IReadOnlyDictionary) according to [this](https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.dbcontextoptions.-ctor?view=efcore-3.1#Microsoft_EntityFrameworkCore_DbContextOptions__ctor_System_Collections_Generic_IReadOnlyDictionary_System_Type_Microsoft_EntityFrameworkCore_Infrastructure_IDbContextOptionsExtension__) page. Would you care to "correct" that part of your question? – MicroservicesOnDDD Feb 11 '20 at 00:53
  • 1
    @MicroservicesOnDDD Updated to specify Implementation rather than Instance – jeubank12 Feb 11 '20 at 00:58
  • What is the definition of "YourDbContextImplementation"? – MicroservicesOnDDD Feb 11 '20 at 16:27
  • @MicroservicesOnDDD just using the most basic implementation of `public class YourDbContextImplementation : DbContext { public YourDbContextImplementation(DbContextOptions options) : base(options) { } }` – jeubank12 Feb 11 '20 at 16:48

0 Answers0