Skip to content

Comments

feat: Added DI overloads for custom config type#199

Merged
steffenskov merged 2 commits intomainfrom
custom-configuration-type
Feb 6, 2026
Merged

feat: Added DI overloads for custom config type#199
steffenskov merged 2 commits intomainfrom
custom-configuration-type

Conversation

@steffenskov
Copy link
Owner

@steffenskov steffenskov commented Feb 6, 2026

Summary by CodeRabbit

  • New Features

    • Added dependency injection overloads for Table and View repositories to support custom repository configuration types.
  • Tests

    • Added unit tests validating custom configuration injection and constructor validation for repository DI.
  • Chores

    • Project version bumped to 1.11.0 and CHANGELOG added; packaging updated to include the changelog.

@coderabbitai
Copy link

coderabbitai bot commented Feb 6, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Refactors DI registration into partial classes and adds overloads to register Table and View repositories with custom configuration types; bumps version to 1.11.0, adds CHANGELOG, adjusts test container image usage, and adds unit tests validating custom-config constructor behavior.

Changes

Cohort / File(s) Summary
Changelog & Version
CHANGELOG.md, Directory.Build.props
Added CHANGELOG entry for 1.11.0 and bumped project version from 1.10.3 to 1.11.0.
Solution & Packaging
Dapper.DDD.Repository.sln, src/Dapper.DDD.Repository/Dapper.DDD.Repository.csproj
Added CHANGELOG.md to solution items and included it as a packaged None file in the project.
DI Refactor (core)
src/Dapper.DDD.Repository.DependencyInjection/DapperRepositoryDependencyInjection.cs
Converted DI helper to a partial class and removed prior monolithic extension methods and delegate definitions (moved to new partial files).
Table Repository DI
src/Dapper.DDD.Repository.DependencyInjection/DapperRepositoryDependencyInjection_Table.cs
Added TableRepositoryConstructorDelegate and multiple AddTableRepository overloads, including custom-configuration generic overload with runtime constructor validation and factory-based registration.
View Repository DI
src/Dapper.DDD.Repository.DependencyInjection/DapperRepositoryDependencyInjection_View.cs
Added ViewRepositoryConstructorDelegate and multiple AddViewRepository overloads, including support for custom configuration types, constructor validation, and delegate-based registration.
Global Usings
src/Dapper.DDD.Repository.DependencyInjection/GlobalUsings.cs
Added global using directives for common DI/Configuration/Repository namespaces.
Test Container Images
tests/.../ContainerFixture.cs (MySql, Sql)
Updated test container builders to supply explicit image tags ("mysql:latest", "mcr.microsoft.com/mssql/server:2022-latest") via constructor instead of parameterless builders.
DI Unit Tests
tests/Dapper.DDD.Repository.UnitTests/DependencyInjection/DapperRepositoryDependencyInjection_TableTests.cs, ..._ViewTests.cs
Added unit tests that assert ArgumentException on mismatched constructors and verify correct injection of custom configuration values into repository instances.

Sequence Diagram

sequenceDiagram
    participant Client as Service Consumer
    participant SC as IServiceCollection
    participant DI as AddRepository<br/>(with CustomConfig)
    participant Validator as Constructor Validator
    participant Factory as Registration Factory
    participant SP as IServiceProvider
    participant Repo as TRepositoryClass<br/>Instance

    Client->>SC: Call AddRepository(Action<CustomConfig>)
    SC->>DI: Extension method invoked
    DI->>Validator: Inspect TRepositoryClass constructors
    alt Constructor matches IOptions<TConfig>
        Validator->>DI: OK
        DI->>SC: Configure options and register factory
        SC->>SC: Store registration
    else Constructor mismatch
        Validator->>DI: Throw ArgumentException
        DI-->>Client: Exception with details
    end

    Client->>SP: Resolve TRepositoryInterface
    SP->>Factory: Invoke factory
    Factory->>SP: Request IOptions<CustomConfig>, IOptions<DefaultConfiguration>
    SP-->>Factory: Return options
    Factory->>Repo: Instantiate TRepositoryClass(options, defaultOptions, provider)
    Factory-->>SP: Return Repo instance
    SP-->>Client: Provide repository
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hopped through code with joyous cheer,
Split the class so intent is clear,
Custom configs now snugly fit,
Tests assure each constructor bit,
Version 1.11.0 — a hop to cheer! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: adding dependency injection overloads that support custom configuration types for Table and View repositories.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch custom-configuration-type

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@CHANGELOG.md`:
- Around line 8-10: The changelog headers use link-reference labels
"[Unreleased]" and "[1.11.0]" but lack their link definitions; add corresponding
reference definitions at the bottom of CHANGELOG.md such as a definition for
[Unreleased] pointing to the compare URL (e.g. .../compare/v1.11.0...HEAD) and a
definition for [1.11.0] pointing to the release tag URL (e.g.
.../releases/tag/v1.11.0) so the header links resolve correctly in Markdown
viewers.

In
`@src/Dapper.DDD.Repository.DependencyInjection/DapperRepositoryDependencyInjection_Table.cs`:
- Around line 46-57: The XML doc for the Table repository overload incorrectly
references ViewAggregateConfiguration; update the summary/typeparam XML for
TConfiguration so it instructs consumers to use TableAggregateConfiguration (not
ViewAggregateConfiguration) — edit the XML comment in
DapperRepositoryDependencyInjection_Table.cs for the generic overload (the
comment describing TConfiguration on the Add table repository overload / the
method that uses TConfiguration) to mention TableAggregateConfiguration as the
expected constructor/configuration type.
🧹 Nitpick comments (4)
tests/Dapper.DDD.Repository.MySql.IntegrationTests/Configuration/ContainerFixture.cs (1)

73-75: Pin the MySQL image to a specific version for reproducible tests.

Using "mysql:latest" makes test runs non-reproducible—the image tag is mutable and can change without notice, potentially breaking tests on new MySQL releases. Testcontainers best practices recommend using explicit version tags like "mysql:8.0.36" or preferably digest-pinned references for maximum reproducibility.

src/Dapper.DDD.Repository.DependencyInjection/DapperRepositoryDependencyInjection_Table.cs (1)

80-93: XML doc is missing the <param> entry for the constructor parameter.

📝 Proposed fix
 	/// <param name="configureOptions">Used to configure the repository via lambda</param>
+	/// <param name="constructor">Custom factory function to create the repository instance</param>
 	public static IServiceCollection AddTableRepository<TAggregate, TAggregateId, TRepositoryInterface,
src/Dapper.DDD.Repository.DependencyInjection/DapperRepositoryDependencyInjection_View.cs (2)

93-106: XML doc is missing the <param> entry for the constructor parameter — same as the Table counterpart.

📝 Proposed fix
 	/// <param name="configureOptions">Used to configure the repository via lambda</param>
+	/// <param name="constructor">Custom factory function to create the repository instance</param>
 	public static IServiceCollection AddViewRepository<TAggregate, TAggregateId, TRepositoryInterface,

141-152: Same missing <param> for constructor in this overload.

📝 Proposed fix
 	/// <param name="configureOptions">Used to configure the repository via lambda</param>
+	/// <param name="constructor">Custom factory function to create the repository instance</param>
 	public static IServiceCollection AddViewRepository<TAggregate, TRepositoryInterface, TRepositoryClass>(

@steffenskov steffenskov merged commit f48dccd into main Feb 6, 2026
2 of 3 checks passed
@steffenskov steffenskov deleted the custom-configuration-type branch February 6, 2026 19:10
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.

1 participant