Skip to content

v7.0.2

Choose a tag to compare

@seesharper seesharper released this 19 May 12:27
· 10 commits to master since this release
f761eb7

Change Log

v7.0.2 (05/19/2026)

Full Changelog

Merged Pull Requests

Fixed issue #606: properly support named Lazy services (04/27/2025) #607 (kemsky)

Fixes issue #606.

I'm not entirely sure that all cases are covered, but tests passed and my issue is resolved.
Fix thread safety of disposableObjects in ServiceContainer.Dispose (05/19/2026) #611 (seesharper)

Summary

  • TrackInstance and Dispose() both accessed disposableObjects (List<IDisposable>) without any synchronization, creating a data race under concurrent load — most visibly when services are still being first-resolved on background threads while the container is being disposed. Depending on .NET version and timing, this manifests as InvalidOperationException: Collection was modified or ArgumentException: Destination array was not long enough.
  • Dispose() also had no guard against the same instance being disposed more than once (e.g. if two container lifetimes happened to return the same object).

Changes

  • TrackInstance — wraps disposableObjects.Add() in lock(container.lockObject), matching the locking pattern already used by Scope.TrackInstance.
  • ServiceContainer.Dispose() — atomically snapshots-and-clears disposableObjects under lockObject, then disposes the snapshot outside the lock so no lock is held during user Dispose() calls (avoids deadlocks). A reference-equality HashSet skips duplicate entries, consistent with how Scope.Dispose() already works.
  • DisposableObjectComparer — new private nested class using RuntimeHelpers.GetHashCode for stable object-identity hashing.
  • Dispose_ConcurrentWithServiceCreation_DoesNotThrow — stress test with 3 concurrent threads (2 resolving services, 1 disposing) over 1000 iterations as a regression guard.

Test plan

  • All 1529 existing tests continue to pass
  • New concurrent stress test passes under the fix

🤖 Generated with Claude Code
Bump version (05/19/2026) #612 (seesharper)

Closed Issues

  • Wrong using at LightInject.Source 7.0.0 nuget package (11/21/2024) #602 (nobyArdor)