Support AddDbContextPool and AddDbContextFactory

Open
#20 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
csharp
Domain
backend, databases

Research direction

Start with the DbContext options registration and the DbCallCountingInterceptor in the library source, and look at how HttpCallCountingHandler gets the per-request DbCallCounter through IHttpContextAccessor. Tests live in tests/NimblePros.Metronome.Tests; add cases for AddDbContextPool and AddDbContextFactory and check that counts stay separate across requests. Done when those tests pass, the new no-provider overload exists, and the README note is removed.

Written by the indexing model from the issue text.

Description

AddMetronomeDbTracking(provider) resolves the scoped DbCallCountingInterceptor, which holds the request's DbCallCounter. That only works with AddDbContext((provider, options) => ...), where the options are built in the request scope.

With AddDbContextPool or AddDbContextFactory, the options are built once and shared. That either fails scope validation or captures one counter and counts calls across all requests. The README currently says these registrations aren't supported.

Proposal

Look up the counter for each command through IHttpContextAccessor, the way HttpCallCountingHandler already does:

  • Register the interceptor as a singleton.
  • On each command, get HttpContext?.RequestServices.GetService<DbCallCounter>(), and skip counting when there's no request.
  • Add an overload that doesn't need the provider argument, and keep the current one for compatibility.

Done when

  • Tests in tests/NimblePros.Metronome.Tests cover pooled and factory-created contexts and confirm that counts stay per request.
  • The README note about these registrations is removed.
Dominant language
C#
Stars
26
Forks
0
Avg merge
6h 17m
Merged PRs (30d)
2

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NimblePros/Metronome

All issues in NimblePros/Metronome

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.