Skip to content

Add a parameterless AddPooledDbContextFactory overload #34658

Closed

Description

@christophe-mommer

Why does the EF Core 9 method AddPooledDbContextFactory<> doesn't have a parameterless method, like AddDbContextFactory<> ?
I'm using the DbContext in two different way:
AddDbContext<> for my MVC pages
AddPooledDbContextFactory<> for my Blazor components integrated in my MVC app

However, I need to switch back to AddDbContextFactory, because the AddPooledDbContextFactory doesn't have any parameterless method and beause of the new way to handle configuration, I need to call ConfigureDbContext<>(opt=>{...}) before my registrations to avoid exceptions.

EF Core version: EF Core 9 RC1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 9
Operating system: Windows 11
IDE: Visual Studio 2022 17.12 p2

Activity

  1. AndriySvyryd commented on Sep 13, 2024

    @AndriySvyryd
    Member

    @christophe-mommer You should be able to call .AddPooledDbContextFactory<T>(_ => {})

  2. changed the title [-]EF Core 9 ConfigureDbContext and PooledDbContextFactory[/-] [+]Add a parameterless AddPooledDbContextFactory overload[/+] on Sep 13, 2024
  3. added this to the Backlog milestone on Sep 13, 2024
  4. christophe-mommer commented on Sep 15, 2024

    @christophe-mommer
    Author

    @AndriySvyryd Hum, not sure about this...
    When I do that, I have en exception:
    System.InvalidOperationException : 'The property ConnectionString wasn't initialized.'

    It only happens when I use DbContexts from the factory

    Here's my configuration:

    services.ConfigureDbContext<HTSLearningDbContext>(ConfigureDbCtx);
    services.AddPooledDbContextFactory<HTSLearningDbContext>(_ => { });
    //services.AddDbContextFactory<HTSLearningDbContext>();
    services.AddDbContext<HTSLearningDbContext>();
    
  5. AndriySvyryd commented on Sep 16, 2024

    @AndriySvyryd
    Member

    services.ConfigureDbContext(ConfigureDbCtx);
    services.AddPooledDbContextFactory(_ => { });
    //services.AddDbContextFactory();
    services.AddDbContext();

    I tried this and it works fine. Can you share a small console app runnable project that shows the exception?

  6. added theissue type on Jun 15, 2025
  7. bkarakaya01 commented on Nov 12, 2025

    @bkarakaya01
    Contributor

    Opened PR #37144 to implement this enhancement (adds parameterless and poolSize overloads for AddPooledDbContextFactory, with tests).
    Maintains full backward compatibility. Would appreciate your guidance or review when convenient.

  8. modified the milestones: Backlog, 11.0.0 on Nov 25, 2025
  9. AndriySvyryd commented on Mar 27, 2026

    @AndriySvyryd
    Member

    Fixed in 8132028

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions