Document IConfigureMarten + DI as the path for modular projection registration (#4326)#4339
Merged
jeremydmiller merged 2 commits intomasterfrom May 7, 2026
Merged
Conversation
…istration Issue #4326 asked for a module-aware AddProjectionWithServices overload, but the existing IConfigureMarten extension point already covers it: the implementation itself is resolved by the host's IoC container, so its constructor can declare whatever dependencies the projection needs and pass them to the projection it registers inside Configure(). This commit makes the pattern explicit: - New ProductProjectionRegistration : IConfigureMarten in projections_with_IoC_services.cs that takes IPriceLookup through its constructor and registers a ProductProjection (the same sample projection AddProjectionWithServices uses) on StoreOptions. - New AddProductModule extension method that demonstrates the module shape: one call wires both the IPriceLookup service AND the IConfigureMarten that uses it. - New use_iconfiguremarten_module_to_register_di_aware_projection integration test that exercises the path end-to-end (host registers the module, an event is appended, and the projection populates Price via the injected dependency). - New "Registering DI-aware projections through IConfigureMarten modules" section in docs/events/projections/ioc.md sourced from the new sample regions (sample_iconfiguremarten_with_di_projection, sample_addproductmodule_with_iconfiguremarten), with a tip that the same pattern applies to subscriptions and IConfigureMarten<TStore>, and a "When to use which" table contrasting the IConfigureMarten path with AddProjectionWithServices. Closes #4326. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The markdownlint job rejected the compact \`|---|---|\` separator on the "When to use which" table in ioc.md. Use the padded \`| --- | --- |\` form so MD060/table-column-style passes.
This was referenced May 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #4326.
The issue asked for a module-aware
AddProjectionWithServicesoverload that could be reached from inside anIConfigureMarten. Per the maintainer's reply on the issue:This is correct —
IConfigureMartenimplementations are resolved by the host's IoC container, so the constructor is already a DI seam. A module just needs to take the projection's dependencies through itsIConfigureMartenconstructor and register the projection insideConfigure(...). The docs didn't make that path explicit, which is what this PR addresses.What changes
ProductProjectionRegistration: IConfigureMartennext to the existingProductProjectionsample. TakesIPriceLookupthrough the constructor, builds aProductProjection, registers it onStoreOptions.AddProductModuleextension method demonstrating the module shape (wires both theIPriceLookupand theIConfigureMartenin one call).use_iconfiguremarten_module_to_register_di_aware_projectionintegration test exercising the path end-to-end — host registers the module, an event is appended, and the projection populatesPricevia the injected dependency.IConfigureMartenmodules" section indocs/events/projections/ioc.md, sourced from the new sample regions. Includes a tip that the same pattern works for subscriptions andIConfigureMarten<TStore>, plus a "When to use which" table contrasting theIConfigureMartenpath withAddProjectionWithServices.Test plan
use_iconfiguremarten_module_to_register_di_aware_projectionpasses on net10.0 against theioc_moduleschema; the assertion thatproduct.Price > 0provesIPriceLookupreached the projection through the IConfigureMarten constructor.npm run docsrenders the new section, the two<!-- snippet: ... -->blocks resolve to the new#regions inprojections_with_IoC_services.cs, and the cross-link to/configuration/hostbuilder#composite-configuration-with-configuremartenresolves.🤖 Generated with Claude Code