Skip to content

Merge Npgsql.DependencyInjection into Npgsql #6590

Closed

Description

@bgrainger

Npgsql.DependencyInjection was added in 2022 in #4521.

The reasons for making its own package were not elucidated in that PR but I would guess it was either to minimize dependencies in Npgsql or avoid incompatibility with other TFMs it supported.

Npgsql now depends on Microsoft.Extensions.Logging.Abstractions which brings in Microsoft.Extensions.DependencyInjection.Abstractions. Both packages also require .NET 8.0 and higher. So there is no practical reason why the code couldn't be moved into Npgsql.

Making the DI types available in the base Npgsql package would simplify the usage story for consumers, who would get access to the DI helpers simply by installing Npgsql.

Two migration approaches I can think of:

  1. Move NpgsqlServiceCollectionExtensions.cs and NpgsqlServiceCollectionExtensions.Obsolete.cs to Npgsql and add [assembly:TypeForwardedTo] to Npgsql.DependencyInjection; this has the downside of preserving obsolete methods.
  2. Add NpgsqlServiceCollectionExtensions.cs (just the non-obsolete methods) to Npgsql and turn all the method bodies in Npgsql.DependencyInjection into simple wrappers that delegate to the new implementation in Npgsql.

Or:
3. Move the code but don't update Npgsql.DependencyInjection at all, just mark it as deprecated in NuGet next time you ship a major version.

Activity

  1. bgrainger commented on May 25, 2026

    @bgrainger
    ContributorAuthor

    (Opening this issue because I'm facing the same situation in MySqlConnector mysql-net/MySqlConnector#1649 and I'm curious on your thoughts about merging DI support into the primary package.)

  2. vonzshik commented on May 26, 2026

    @vonzshik
    Contributor

    The reasons for making its own package were not elucidated in that PR but I would guess it was either to minimize dependencies in Npgsql

    Yep, that's pretty much that.

    Npgsql now depends on Microsoft.Extensions.Logging.Abstractions which brings in Microsoft.Extensions.DependencyInjection.Abstractions.

    Microsoft.Extensions.Logging.Abstractions only started to depend on Microsoft.Extensions.DependencyInjection.Abstractions with .NET 8, while that package was added around .NET 6/7, which is an additional reason as to why things were like this.

    Overall, sounds reasonable to move whatever we need to the main dll.

  3. roji commented on May 27, 2026

    @roji
    Member

    Yeah, this is mainly historical. I'll just merge this into the main package.

  4. self-assigned this
    on May 27, 2026
  5. added theissue type on May 27, 2026
  6. added this to the 11.0.0 milestone on May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions