Skip to content

Add parameterless overloads for AddPooledDbContextFactory<TContext>#37144

Merged
AndriySvyryd merged 1 commit intodotnet:mainfrom
bkarakaya01:feature/add-paramless-pooled-factory
Feb 26, 2026
Merged

Add parameterless overloads for AddPooledDbContextFactory<TContext>#37144
AndriySvyryd merged 1 commit intodotnet:mainfrom
bkarakaya01:feature/add-paramless-pooled-factory

Conversation

@bkarakaya01
Copy link
Contributor

Summary

Introduces two new overloads (parameterless + poolSize) that delegate to the existing
(IServiceProvider, DbContextOptionsBuilder) overload with a no-op action.

Aligns pooled factory ergonomics with the centralized configuration model
ConfigureDbContext<TContext>.

Keeps full backward compatibility; no existing signature or behavior changed.


Motivation

When using ConfigureDbContext<TContext>, callers shouldn’t have to pass an extra configuration lambda
to pooled factory registration; options should flow automatically.


Design

  • New overloads simply call the existing overload with static (_, __) => { }.
  • XML docs reference the related ConfigureDbContext overload; no behavioral drift.
  • No changes to pooling internals, service lifetimes, or registrations.

Tests

Added AddPooledDbContextFactoryParameterlessTest covering:

  • ✅ Parameterless factory honors ConfigureDbContext provider (InMemory).
  • ✅ Custom poolSize overload resolves correctly.
  • ✅ Scoped resolution of TContext works.
  • ✅ Pool is registered as singleton.
  • ✅ Without configuration, first provider use throws.

Compatibility

  • Additive public API only.
  • No source or binary breaking changes.
  • Full XML documentation provided for all new public members.

Issues

Fixes #34658

@bkarakaya01 bkarakaya01 requested a review from a team as a code owner November 12, 2025 11:23
@bkarakaya01
Copy link
Contributor Author

@dotnet-policy-service agree

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces two parameterless overloads for AddPooledDbContextFactory<TContext> to improve ergonomics when using the centralized configuration model via ConfigureDbContext<TContext>. The overloads delegate to the existing implementation with a no-op action, allowing options to flow automatically without redundant configuration lambdas.

  • Adds parameterless AddPooledDbContextFactory<TContext>() overload
  • Adds AddPooledDbContextFactory<TContext>(int poolSize) overload with custom pool size
  • Includes comprehensive test coverage validating integration with ConfigureDbContext

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
src/EFCore/Extensions/EntityFrameworkServiceCollectionExtensions.cs Adds two new public API overloads for pooled factory registration without configuration lambdas, delegating to existing overload with static no-op action
test/EFCore.Tests/Infrastructure/AddPooledDbContextFactoryParameterlessTest.cs New test file with 5 tests covering parameterless factory scenarios: ConfigureDbContext integration, custom pool size, scoped resolution, singleton pool registration, and error handling without configuration

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@roji roji force-pushed the main branch 2 times, most recently from 249ae47 to 6b86657 Compare January 13, 2026 17:46
…igning pooled factory with ConfigureDbContext<TContext>.

Fixes dotnet#34657
@AndriySvyryd AndriySvyryd force-pushed the feature/add-paramless-pooled-factory branch from db591f6 to 97ff8ad Compare February 26, 2026 19:39
@AndriySvyryd AndriySvyryd enabled auto-merge (squash) February 26, 2026 19:42
@AndriySvyryd
Copy link
Member

Thanks for your contribution

@AndriySvyryd AndriySvyryd merged commit 8132028 into dotnet:main Feb 26, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants