feat: map a view from the service locator under its own contract by glennawatson · Pull Request #145 · reactiveui/ReactiveUI.Binding.SourceGenerators · GitHub
Skip to content

feat: map a view from the service locator under its own contract - #145

Merged
glennawatson merged 1 commit into
mainfrom
feat/map-from-service-locator-contract
Sep 26, 2026
Merged

glennawatson merged 1 commit into
mainfrom
feat/map-from-service-locator-contract

Conversation

@glennawatson

Copy link
Copy Markdown
Contributor

Summary

MapFromServiceLocator can now ask the service locator for a view under a contract, so a contracted IViewFor<T> registration is reachable.

  • New overload MapFromServiceLocator<TViewModel, TView>(contract, serviceContract). The mapping resolves under contract, and asks the service locator for TView under serviceContract. A view not registered under that contract throws InvalidOperationException naming the contract.
  • The existing overloads keep their behaviour. MapFromServiceLocator<TViewModel, TView>(contract) still asks the service locator with no contract; its docs now point at the new overload.
  • New example MapContractedViewFromServiceLocator registers a default and a contracted IViewFor<TodoItem> in the service locator and maps each.

Why

A view model with a default view and a contracted view, both registered in the service locator as IViewFor<T>, could not be mapped by contract: MapFromServiceLocator<T, IViewFor<T>>(contract) always returned the default registration. Passing the mapping's contract through would break code that maps a concrete view, registered with no contract, under a contract, so the service contract is a separate argument.

Breaking changes

None. The change adds an overload.

How this was verified

  • Runtime tests cover a default and a contracted IViewFor<T> registration mapped side by side, and the error for a missing contracted registration.
  • Ran the Linux examples suite and the Windows examples on a real Windows machine; the new example prints what its comments say.

Notes for the reviewer

  • Start with ViewMappingBuilder.MapFromServiceLocator<TViewModel, TView>(string?, string?).
  • Mechanical: the PublicAPI baseline entries for the new overload in both runtime leaves.

Checklist

  • I have read the Contribute guide
  • The PR title follows Conventional Commits
  • Tests cover this change, or the summary says why they do not
  • New or changed public API has XML documentation

- Add MapFromServiceLocator<TViewModel, TView>(contract, serviceContract).
- A contracted IViewFor<T> registration was unreachable: the lookup always used no contract.
- The existing overloads keep asking with no contract.
@glennawatson
glennawatson enabled auto-merge (squash) September 26, 2026 11:54
@codecov

codecov Bot commented Sep 26, 2026

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

@glennawatson
glennawatson merged commit 66214dc into main Sep 26, 2026
22 checks passed
@glennawatson
glennawatson deleted the feat/map-from-service-locator-contract branch September 26, 2026 12:18
@github-actions

Copy link
Copy Markdown

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant