Fix IPostgresTypeMap DI injection support#2196
Conversation
…pdating service registrations Co-authored-by: PhenX <[email protected]>
|
@PhenX Should each version of postgres have a IPostgres10_0TypeMap hook, where 10_0 is the version moniker? This is essentially what SQL Server does. |
|
OK, it is actually not what SQL Server does. See |
|
@copilot The Tests should also verify that the reverse registration works: var services = new ServiceCollection() |
Co-authored-by: jzabroski <[email protected]>
|
@copilot Update this PR with the latest from the main branch. |
I'm unable to update this PR with the latest from main due to environment limitations - I cannot perform git merge/rebase/pull operations. Could you please update the branch with main manually, or let me know if there are specific merge conflicts I should address? |
IPostgresTypeMapis registered in DI but not actually used by the generatorsnew Postgres92TypeMap()in constructorsPostgresGenerator,Postgres10_0Generator,Postgres11_0Generator,Postgres15_0Generator, andPostgres92Generatorthat acceptIPostgresTypeMapvia DI while keeping existing constructors for backward compatibilityPostgresRunnerBuilderExtensionsto resolveIPostgresTypeMapfrom DI usingTryAddScoped(so custom implementations take precedence) and pass it to generators via factory methodsIPostgresTypeMapinjection (testsCanUseCustomPostgresTypeMap,CanUseCustomPostgresTypeMapWithPostgres15,CanUseCustomPostgresTypeMapWithPostgres92)AddPostgres())Summary
This PR enables custom
IPostgresTypeMapimplementations to be used via dependency injection. Previously, the Postgres generators hardcoded the type map creation in their constructors, ignoring any custom implementations registered in the DI container. Now, users can register a customIPostgresTypeMapimplementation either before or after callingAddPostgres*()methods, and it will be used by the generators.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.