Skip to content

Document IConfigureMarten + DI as the path for modular projection registration (#4326)#4339

Merged
jeremydmiller merged 2 commits intomasterfrom
docs-issue-4326-iconfiguremarten-projection-di
May 7, 2026
Merged

Document IConfigureMarten + DI as the path for modular projection registration (#4326)#4339
jeremydmiller merged 2 commits intomasterfrom
docs-issue-4326-iconfiguremarten-projection-di

Conversation

@jeremydmiller
Copy link
Copy Markdown
Member

Summary

Closes #4326.

The issue asked for a module-aware AddProjectionWithServices overload that could be reached from inside an IConfigureMarten. Per the maintainer's reply on the issue:

If you're registering an IConfigureMarten, you can poke whatever dependencies you want through the constructor function.

This is correct — IConfigureMarten implementations 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 its IConfigureMarten constructor and register the projection inside Configure(...). The docs didn't make that path explicit, which is what this PR addresses.

What changes

  • New ProductProjectionRegistration : IConfigureMarten next to the existing ProductProjection sample. Takes IPriceLookup through the constructor, builds a ProductProjection, registers it on StoreOptions.
  • New AddProductModule extension method demonstrating the module shape (wires both the IPriceLookup and the IConfigureMarten in one call).
  • New use_iconfiguremarten_module_to_register_di_aware_projection integration test exercising 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. Includes a tip that the same pattern works for subscriptions and IConfigureMarten<TStore>, plus a "When to use which" table contrasting the IConfigureMarten path with AddProjectionWithServices.

Test plan

  • use_iconfiguremarten_module_to_register_di_aware_projection passes on net10.0 against the ioc_module schema; the assertion that product.Price > 0 proves IPriceLookup reached the projection through the IConfigureMarten constructor.
  • npm run docs renders the new section, the two <!-- snippet: ... --> blocks resolve to the new #regions in projections_with_IoC_services.cs, and the cross-link to /configuration/hostbuilder#composite-configuration-with-configuremarten resolves.

🤖 Generated with Claude Code

jeremydmiller and others added 2 commits May 7, 2026 09:25
…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.
@jeremydmiller jeremydmiller merged commit 675815b into master May 7, 2026
6 checks passed
@jeremydmiller jeremydmiller deleted the docs-issue-4326-iconfiguremarten-projection-di branch May 7, 2026 14:48
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.

Enable AddProjectionWithServices on modules in IConfigureMarten

1 participant