Skip to content

Address DI registration review findings#5

Merged
jaak0b merged 1 commit into
mainfrom
fix/di-review-followups
Jun 5, 2026
Merged

Address DI registration review findings#5
jaak0b merged 1 commit into
mainfrom
fix/di-review-followups

Conversation

@jaak0b

@jaak0b jaak0b commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Follow-ups from a review of the Autofac and Microsoft.Extensions.DependencyInjection registration code. Registration was already correct and behaviour-equivalent; these address the smaller findings.

Changes

  1. Capability symmetryIZ21CommandStation now also extends IProgrammingControl, IFeedbackControl and IFastClockControl (the station already implemented them). Previously these three were reachable only by casting the concrete instance, while the other four capabilities were part of the interface. No DI registration change needed — the station is already registered.
  2. Idempotent dispose — MS.DI's ICommandStation registration forwards to the IZ21CommandStation singleton via a factory, so MS.DI captures the same instance for disposal twice and calls Dispose() twice on provider teardown. Harmless today (it only disposes a Timer), but Z21CommandStation.Dispose is now guarded so it stays safe if cleanup grows.
  3. Test parity — added an Autofac end-to-end inbound-dispatch test (spy transport -> received bytes -> capability event) mirroring the MS.DI one, so an Autofac wiring regression is caught; plus capability-exposure tests in both DI suites.
  4. DocsCLAUDE.md corrected: the dispatcher is a plain singleton and a constructor dependency of the station (resolving the station wires inbound handling); there is no eager auto-activation.

Verification

Full solution test run is green: Z21.Client 656, Z21.DependencyInjection 7, Z21.Autofac 8, CommandStation.Transport.Udp 14. The new IZ21CommandStationContractTest was written test-first (red before the interface change, green after).

- IZ21CommandStation now extends IProgrammingControl, IFeedbackControl and
  IFastClockControl, the remaining capabilities the station already implements,
  so all capabilities are reachable through the resolved station instead of only
  via a cast on the concrete type.
- Make Z21CommandStation.Dispose idempotent. The MS.DI ICommandStation
  registration forwards to the IZ21CommandStation singleton via a factory, so the
  same instance is captured for disposal twice; the guard keeps a second Dispose
  a no-op and protects future non-idempotent cleanup.
- Add an Autofac end-to-end inbound-dispatch test (spy transport -> received bytes
  -> capability event) mirroring the existing MS.DI test, plus capability-exposure
  tests in both DI suites, so the two containers stay behaviour-equivalent.
- Update CLAUDE.md: the dispatcher is a plain singleton and a constructor
  dependency of the station (no eager auto-activation).
@jaak0b jaak0b merged commit 1b4f104 into main Jun 5, 2026
6 checks passed
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