Skip to content

feat(core)!: add safe View and ViewModel lifecycle helpers - #328

Merged
VPDPersonal merged 17 commits into
mainfrom
feat/safe-view-lifecycle
Nov 20, 2026
Merged

VPDPersonal merged 17 commits into
mainfrom
feat/safe-view-lifecycle

Conversation

@VPDPersonal

@VPDPersonal VPDPersonal commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Warning

Replace explicit MonoViewExtensions and MonoViewModelExtensions calls with ViewExtensions and ViewModelExtensions, respectively. Call DeinitializeView() without an explicit type argument. Reinitialize, DeinitializeView and both DisposeView overloads reject destroyed Unity objects. Strict ViewModel initialization and disposal also reject destroyed Unity objects. Initialization reports two invalid arguments in an AggregateException. Use the corresponding *Safely methods to skip missing objects. Destruction methods use interface overloads, and DestroyViewModelAndGameObject now returns void.

Why

Optional Views and lifecycle callbacks can require callers to wrap cleanup or reinitialization in exception handling.

What

  • Skip null Views and destroyed Unity objects.
  • Log lifecycle exceptions to the Unity Console.
  • Return the previous ViewModel on successful View cleanup or reinitialization.
  • Continue batch initialization when an individual View fails.
  • Attempt Unity ViewModel destruction even when disposal fails.

Start with ViewExtensions.cs.

+ IViewModel? ReinitializeSafely(this IView? view, IViewModel? newViewModel)
- IViewModel? DeinitializeView<T>(this T view) where T : class, IView
+ IViewModel? DeinitializeView(this IView view)
+ IViewModel? DeinitializeViewSafely(this IView? view)
+ IViewModel? DisposeViewSafely<T>(this T? view) where T : class, IView, IDisposable
+ IViewModel? DisposeViewSafely(this IView? view)
+ void InitializeViewSafely(this IViewModel? viewModel, IView? view)
+ void InitializeViewsSafely(this IViewModel? viewModel, params IView?[]? views)
+ void InitializeViewsSafely<T>(this IViewModel? viewModel, List<T>? views) where T : IView?
+ void InitializeViewsSafely(this IViewModel? viewModel, IEnumerable<IView?>? views)
+ void DisposeViewModelSafely<T>(this T? viewModel) where T : class, IViewModel, IDisposable
+ void DisposeViewModelSafely(this IViewModel? viewModel)
+ IViewModel? DestroyViewSafely(this IView? view)
+ IViewModel? DestroyViewAndGameObjectSafely(this IView? view)
+ GameObject? DestroyViewModelSafely(this IViewModel? viewModel)
+ void DestroyViewModelAndGameObjectSafely(this IViewModel? viewModel)
Verification
  • Unity 6000.6.5f1 Editor compilation completed without errors.
  • Full Unity suites passed 4,087 EditMode tests and 361 PlayMode tests. The Zenject fixture scene was enabled temporarily in the PlayMode verification checkout.
  • The ViewModel destruction move passed 44 EditMode and 9 PlayMode tests.
  • The View destruction move passed 57 EditMode and 9 PlayMode tests.
  • DocFX regenerated the API and the freshness check passed.
  • node scripts/check-package-files.mjs passed on the PR checkout.

- Log lifecycle exceptions and accept null Views.
- Cover successful calls and exception handling in EditMode.
@VPDPersonal VPDPersonal added type: feature New feature or capability area: runtime Runtime / player code area: docs Documentation / knowledge wiki labels Nov 20, 2026
- Check Unity object liveness before lifecycle calls.
- Cover destroyed Views across all safe overloads in EditMode.
- Skip null and destroyed Unity objects before initialization or disposal.
- Log exceptions and continue batch initialization after individual failures.
@VPDPersonal VPDPersonal changed the title feat(core): add safe View lifecycle helpers feat(core): add safe View and ViewModel lifecycle helpers Nov 20, 2026
- Use the IView receiver for deinitialization.
- Reject destroyed Unity Views in both disposal overloads.
- Share the disposal profiler marker.
@VPDPersonal VPDPersonal added the breaking-change Backwards-incompatible change requiring major version bump label Nov 20, 2026
@VPDPersonal VPDPersonal changed the title feat(core): add safe View and ViewModel lifecycle helpers feat(core)!: add safe View and ViewModel lifecycle helpers Nov 20, 2026
- Use the same Unity liveness check for Views and ViewModels.
- Keep concrete batch enumeration and log iterator failures.
- Reject destroyed Unity references in strict lifecycle calls.
- Report both invalid initialization arguments and remove disposal profiler markers.
- Log cleanup failures after attempting destruction.
- Cover component and GameObject destruction through both receiver types.
- Merge the destruction methods into the partial ViewExtensions type.
- Preserve Unity script metadata and document explicit call migration.
- Merge destruction methods into partial ViewModelExtensions.
- Preserve script metadata and document explicit call migration.
- Match the null handling of View destruction.
- Verify all overloads and regenerate the API reference.
- Keep interface overloads and make whole-object ViewModel destruction void.
- Preserve cleanup exceptions in regular calls and log them in safe calls.
- Normalize destroyed GameObject results and update lifecycle tests.
@VPDPersonal
VPDPersonal marked this pull request as ready for review November 20, 2026 17:23
@github-actions github-actions Bot added the status: needs-review Ready for review label Nov 20, 2026
@VPDPersonal
VPDPersonal merged commit 644e259 into main Nov 20, 2026
21 checks passed
@VPDPersonal
VPDPersonal deleted the feat/safe-view-lifecycle branch November 20, 2026 17:36
@github-actions github-actions Bot removed the status: needs-review Ready for review label Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: docs Documentation / knowledge wiki area: runtime Runtime / player code breaking-change Backwards-incompatible change requiring major version bump type: feature New feature or capability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant