Repository navigation
Add DI extension packages for scoped, shared-connection DAO registration - #69
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Co-authored-by: twogood <189982+twogood@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The focused implementation matches the stated lifetime requirements and includes representative transaction tests and documentation.
0 open findings
What changed in this PR
Adds DI packages that simplify scoped DAO registration and safely support cross-DAO transactions through a shared connection.
Changes:
- Adds gateway-agnostic and Dapper-specific DI extensions.
- Documents connection lifetime and ownership requirements.
- Tests commit and rollback across separate DAOs sharing one connection.
| File | Description |
|---|---|
README.md |
Documents shared-connection registration. |
Activout.DatabaseClient.Test/SharedConnectionDependencyInjectionTest.cs |
Tests cross-DAO commit and rollback. |
Activout.DatabaseClient.Test/Activout.DatabaseClient.Test.csproj |
Adds DI test dependencies. |
Activout.DatabaseClient.sln |
Registers both new projects. |
Activout.DatabaseClient.Extensions.DependencyInjection/ServiceCollectionExtensions.cs |
Adds generic DAO registration. |
Activout.DatabaseClient.Extensions.DependencyInjection/README.md |
Documents generic DI usage. |
Activout.DatabaseClient.Extensions.DependencyInjection/Activout.DatabaseClient.Extensions.DependencyInjection.csproj |
Defines the generic DI package. |
Activout.DatabaseClient.Dapper.Extensions.DependencyInjection/ServiceCollectionExtensions.cs |
Adds Dapper-specific registration. |
Activout.DatabaseClient.Dapper.Extensions.DependencyInjection/README.md |
Documents Dapper lifetime rules. |
Activout.DatabaseClient.Dapper.Extensions.DependencyInjection/Activout.DatabaseClient.Dapper.Extensions.DependencyInjection.csproj |
Defines the Dapper DI package. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@copilot Clean up the solution file (.sln), now you added a lot of x86 and x64 rows, while |
Co-authored-by: twogood <189982+twogood@users.noreply.github.com>
Removed all the x86/x64 rows from the .sln, plus the |
|
@copilot Ändra TargetFramework till .net 10 |
Co-authored-by: twogood <189982+twogood@users.noreply.github.com>
Head branch was pushed to by a user without write access
* Add DI extension packages for scoped, shared-connection DAO registration (#69) * Apply remaining changes Co-authored-by: twogood <189982+twogood@users.noreply.github.com> * Implement error handling for Enumerable method invocation Added error handling for method invocation to capture and rethrow inner exceptions. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: David Eriksson <david@activout.se> * Make unsupported collection test construct DAO outside Assert.Throws Co-authored-by: twogood <189982+twogood@users.noreply.github.com> --------- Signed-off-by: David Eriksson <david@activout.se> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: twogood <189982+twogood@users.noreply.github.com> Co-authored-by: David Eriksson <david@activout.se> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Cross-DAO transactions only work if every DAO's gateway uses the same
IDbConnection. That requirement is easy to miss and tedious to wire up in DI apps. This PR adds registration helpers that make the shared scoped connection the default, and documents the connection lifetime rules.Activout.DatabaseClient.Extensions.DependencyInjection(new package)Microsoft.Extensions.DependencyInjection.Abstractionsand the core package.AddDatabaseClient<TDao>(Func<IServiceProvider, IDatabaseGateway>, ServiceLifetime = Scoped), which works with any gateway.Activout.DatabaseClient.Dapper.Extensions.DependencyInjection(new package)AddDapperDatabaseClient<TDao>(parameterPrefix = "@", lifetime = Scoped).DapperGatewayover theIDbConnectionregistered in the container.Docs
IDbConnectionmust be scoped so DAOs in a scope share it.DapperGatewayopens the connection if it is closed.Tests
SharedConnectionDependencyInjectionTestresolves two DAO interfaces from one scope. It begins a transaction on one DAO, writes through the other, then commits in one case and rolls back in another.Review notes:
dotnet packon all packable projects, so the new packages are picked up without CI changes.