Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 26, 2025

This PR documents the ConfigureDbContext method and clarifies the breaking change in EF Core 8.0 regarding multiple AddDbContext calls.

Overview

This PR addresses two related issues:

Breaking Changes Documentation (EF Core 8.0)

Enhanced the breaking changes documentation for multiple AddDbContext calls with:

  • Streamlined descriptions: Removed redundant code examples from "Old behavior" and "New behavior" sections for better readability
  • Clear rationale: Updated "Why" section to explain that the change was made to be consistent with the new ConfigureDbContext method, with a link to detailed documentation
  • Comprehensive mitigations: Added four different migration strategies:
    1. Reordering registrations to place desired configuration last
    2. Removing conflicting registrations when possible
    3. Using conditional registration checks
    4. Using the new ConfigureDbContext method (EF Core 9.0+)

ConfigureDbContext Documentation (EF Core 9.0)

Added comprehensive documentation for the ConfigureDbContext method introduced in EF Core 9.0:

Key Capabilities

  • Configuration composition: Enables adding non-conflicting configuration
  • Reusable components: Perfect for creating testing utilities or library configurations
  • Provider-agnostic options: Add logging, interceptors, or other options without knowing the database provider
  • Provider-specific configuration: Apply provider-specific options without connection strings using methods like ConfigureSqlEngine

Documentation Includes

  • API reference link to ConfigureDbContext method
  • Basic usage examples showing configuration composition
  • Provider-specific configuration patterns without connection strings
  • Configuration precedence behavior with multiple calls
  • Note about provider replacement limitations

Sample Code

  • Integrated ConfigureDbContext sample code into the main ConfiguringDbContext.csproj project
  • Sample code is now in ConfigureDbContextSample.cs in the main samples directory
  • All samples compile and run successfully with .NET 9.0 and EF Core 9.0
  • Clean code structure with proper region boundaries excluding the service provider instantiation
  • Fixed nullable annotation warnings and entry point conflicts
  • All package references updated to version 9.0.0 for consistency
  • Sample class properly named as ConfigureDbContextSample

Technical Clarifications

  • ConfigureDbContext availability: Introduced in EF Core 9.0 (not 8.0)
  • Breaking change: Multiple AddDbContext calls now use last-wins precedence (changed in EF Core 8.0)
  • Configuration composition: Non-conflicting options (logging, interceptors) compose together; conflicting options (providers) use last-wins
  • Design consistency: The EF Core 8.0 breaking change was made to be consistent with the future ConfigureDbContext method
  • Provider replacement: Configuring a different provider doesn't remove previous provider configuration; a note is included

Fixes #4588
Fixes #4923

Original prompt

This section details on the original issue you should resolve

<issue_title>Document ConfigureDbContext </issue_title>
<issue_description>Also document the minor breaking change when AddDbContext is called multiple times with different options, see dotnet/efcore#32518</issue_description>

<agent_instructions>Note that the breaking change is in 8.0</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #4588

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits September 26, 2025 20:27
… 8.0

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Document ConfigureDbContext Document ConfigureDbContext behavior and AddDbContext precedence changes in EF Core 8.0 Sep 26, 2025
Copilot finished work on behalf of AndriySvyryd September 26, 2025 20:30
@Copilot Copilot AI requested a review from AndriySvyryd September 26, 2025 20:30
Copy link
Member

@AndriySvyryd AndriySvyryd left a comment

Choose a reason for hiding this comment

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

https://gh.io/copilot-coding-agent-docs Update progress by changing the PR description to a nicely formatted summary of the changes that includes fixing #4923

…nd improve breaking changes

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 30, 2025

https://gh.io/copilot-coding-agent-docs Update progress by changing the PR description to a nicely formatted summary of the changes that includes fixing https://github.com/dotnet/EntityFramework.Docs/...

Updated PR description with a nicely formatted summary that includes fixing both issues #4588 and #4923.

@Copilot Copilot AI changed the title Document ConfigureDbContext behavior and AddDbContext precedence changes in EF Core 8.0 Document ConfigureDbContext method and AddDbContext precedence changes in EF Core 8.0 Sep 30, 2025
@Copilot Copilot AI requested a review from AndriySvyryd September 30, 2025 18:18
Copilot finished work on behalf of AndriySvyryd September 30, 2025 18:18
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
@Copilot Copilot AI requested a review from AndriySvyryd September 30, 2025 19:14
Copilot finished work on behalf of AndriySvyryd September 30, 2025 19:14
… remove BlogContext region, adjust endregion placement

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
@Copilot Copilot AI requested a review from AndriySvyryd September 30, 2025 19:31
Copilot finished work on behalf of AndriySvyryd September 30, 2025 19:31
…ppets

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot finished work on behalf of AndriySvyryd September 30, 2025 19:39
@Copilot Copilot AI requested a review from AndriySvyryd September 30, 2025 19:39
@AndriySvyryd AndriySvyryd marked this pull request as ready for review September 30, 2025 19:44
@AndriySvyryd AndriySvyryd requested a review from a team September 30, 2025 19:45
@AndriySvyryd AndriySvyryd marked this pull request as draft September 30, 2025 20:00
…te sample directory

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
@Copilot Copilot AI requested a review from AndriySvyryd September 30, 2025 21:58
Copilot finished work on behalf of AndriySvyryd September 30, 2025 21:58
…o net9.0

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot finished work on behalf of AndriySvyryd September 30, 2025 23:54
@AndriySvyryd AndriySvyryd marked this pull request as ready for review September 30, 2025 23:56
@AndriySvyryd AndriySvyryd requested a review from a team September 30, 2025 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document DbContextOptions service registration breaking change Document ConfigureDbContext
2 participants