NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
NuGet · #2167 most downloaded on NuGet
An ultra lightweight Inversion of Control container for the .Net framework. See LightInject.Source for the source distribution.
Last release 11 days ago
30 Sep 2026
Release timing varies
gaps range from 8 days to 1.5 years
Rarely documented
notes for 11 of the last 60 stable releases
10 versions withdrawn
withdrawn after publishing
127 years old
102 releases · first in 1900
Synchronize CanGetInstance with delegate creation (09/25/2026) #616 ( seesharper )
Synchronize CanGetInstance with delegate creation (09/25/2026) #616 (seesharper)
Fixes #614
CreateDelegate holds lockObject while building emit methods, but CanGetInstance walks the same GetEmitMethod → CreateEmitMethodForUnknownService path without the lock. That path can register closed generic services, appending to the List<ServiceRegistration> / List<EmitMethodInfo> values in allRegistrations / allEmitters while another thread enumerates them in CreateEmitMethodForEnumerableServiceServiceRequest:
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Linq.Enumerable+SelectManySingleSelectorIterator...
at LightInject.ServiceContainer.CreateEmitMethodForEnumerableServiceServiceRequest(...)
With LightInject.Microsoft.DependencyInjection, CanGetInstance backs IServiceProviderIsService, which ActivatorUtilities (Hangfire, MVC, etc.) calls at runtime, so this shows up under production load.
Take lockObject in CanGetInstance. Monitor is reentrant, so nested calls from within CreateDelegate are unaffected.
Issue614 runs CanGetInstance and GetInstance concurrently for many open generic enumerables with MS compatibility enabled. It fails consistently on master (corrupted lists from concurrent List.Add) and passes with the fix. Full suite passes (1562 tests).
A separate, pre-existing issue where closed generic enumerables accumulate duplicate items in MS compatibility mode will be addressed in a follow-up PR.
🤖 Generated with Claude Code
Only close open generic registrations once per closed service type (09/25/2026) #617 (seesharper)
Follow-up to #616 (found while investigating #614).
With EnableMicrosoftCompatibility, CreateEmitMethodForEnumerableServiceServiceRequest closes all open generic registrations and appends them to allEmitters every time an enumerable emit method is created for a closed generic service type. Emit methods are created more than once for the same type (as a dependency, as a root service, via CanGetInstance), so items accumulate:
container.Register(typeof(IBehavior<>), typeof(FirstBehavior<>));
container.Register(typeof(IBehavior<>), typeof(SecondBehavior<>));
container.GetInstance<Handler<int>>(); // IEnumerable<IBehavior<int>> -> 2 items
container.GetInstance<IEnumerable<IBehavior<int>>>(); // 4 items (expected 2)Calling CanGetInstance first gives 4 and 6. A closed generic that was first registered through a single-service request (CreateEmitMethodBasedOnClosedGenericServiceRequest) was also added again by the enumerable path. For MediatR users this means pipeline behaviors can run multiple times.
Without Microsoft compatibility the problem was masked because emitters are stored per service name (TryAdd).
Track, per closed generic service type, which open generic registrations (identified by their unique RegistrationOrder) have already been closed, and skip them on subsequent requests. The single-service path marks its registration too, when the closed registration uses the same service name as the open one.
ClosedGenericEnumerableTests covers resolving the enumerable multiple times, after CanGetInstance, and after a single-service resolve, with and without Microsoft compatibility. The MS-compat cases fail on master and pass with the fix.🤖 Generated with Claude Code
Bump version to 7.1.1 (09/30/2026) #619 (seesharper)
Bumps the version to 7.1.1.
Includes:
CanGetInstance with delegate creation (fixes #614)🤖 Generated with Claude Code
One column per quarter.
Align keyed service tests with MS.DI spec and fix AnyKey enumeration (05/21/2026) #613 ( seesharper )
Align keyed service tests with MS.DI spec and fix AnyKey enumeration (05/21/2026) #613 (seesharper)
KeyedMicrosoftTests.cs with the upstream KeyedDependencyInjectionSpecificationTests.cs from dotnet/runtime"*") registrations were incorrectly included in IEnumerable<T> keyed service resolutionKeyedMicrosoftTests.cs)ResolveKeyedServicesAnyKeyWithAnyKeyRegistration: expects 4 services (not 5); AnyKey registrations are excluded from enumerationResolveKeyedServicesSingletonInstanceWithAnyKey: AnyKey registrations are not included when listing services by a specific keyResolveKeyedSingletonFromScopeServiceProvider and ResolveKeyedScopedFromScopeServiceProvider: added assertions that direct AnyKey lookup throwsCombinationalRegistration, ResolveKeyedServicesAnyKeyConsistency, ResolveKeyedServicesAnyKeyConsistencyWithAnyKeyRegistration, ResolveKeyedServicesAnyKeyOrdering, ResolveWithAnyKeyQuery_Constructor, ResolveWithAnyKeyQuery_Constructor_Duplicates, ResolveWithAnyKeyQuery_InstanceProvided, ResolveWithAnyKeyQuery_InstanceProvided_Duplicates, ResolveRequiredKeyedServiceThrowsIfNotFound, SimpleServiceKeyedResolutionLightInject.cs)In CreateEmitMethodForEnumerableServiceServiceRequest, two cases fixed (both variance and no-variance branches):
GetKeyedServices(AnyKey): added && k.ServiceName != "*" so the "*" registration itself is not returnedGetKeyedServices("some-key"): removed || k.ServiceName == "*" so AnyKey wildcard registrations don't appear in specific-key enumerationsSingle-service resolution with AnyKey wildcard fallback is unaffected.
🤖 Generated with Claude Code
Fixed issue #606 : properly support named Lazy services (04/27/2025) #607 ( kemsky )
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)
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).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.🤖 Generated with Claude Code
Bump version (05/19/2026) #612 (seesharper)
Removed unused usings (11/19/2024) #603 ( seesharper )
Removed unused usings (11/19/2024) #603 (seesharper)
Bump version (11/19/2024) #604 (seesharper)
Master (08/12/2023) #591 ( oliverscode )
Master (08/12/2023) #591 (oliverscode)
Fix test code errors
Fix typo in readme.md (08/15/2023) #592 (tompazourek)
Added compatibility with Microsoft.Extensions.DependencyInjection for keyed services. (11/06/2024) #599 (seesharper)
This PR adds the EnableMicrosoftCompatibility option which makes LightInject compatible with Microsoft.Extensions.DependencyInjection.
This includes support for keyed services which is now part of Microsoft.Extensions.DependencyInjection
Use Net8 and bumped all deps (11/06/2024) #601 (seesharper)
Update LightInject.cs (01/01/2023) #584 ( haavamoa )
Update LightInject.cs (01/01/2023) #584 (haavamoa)
Bugfix in GenericTypeMapper (05/08/2023) #588 (seesharper)
This PR fixes a bug that caused the GenericTypeMapper to return multiple candidates even if only one of the candidates actually implemented the requested service
Bump version number and dependencies (05/08/2023) #589 (seesharper)
Call Completed handler on Dispose and DisposeAsync (12/31/2022) #583 ( seesharper )
Call Completed handler on Dispose and DisposeAsync (12/31/2022) #583 (seesharper)
Added decorator test to prove that we can return without recorating (10/03/2022) #576 ( seesharper )
Added decorator test to prove that we can return without recorating (10/03/2022) #576 (seesharper)
Fixed issue #578 by setting serviceName to string.Empty if no registrations for the specified serviceType are found. (10/23/2022) #579 (mesakomarevich)
Fixed issue #578 and updated the unit tests that call CanGetInstance to cover null, empty, and whitespace values for the serviceName argument.
Bugfix dispose decorators as singleton (12/29/2022) #582 (seesharper)
Only compile with asyncdisposable for netcoreapp3.1 and above (09/19/2022) #574 ( seesharper )
Only compile with asyncdisposable for netcoreapp3.1 and above (09/19/2022) #574 (seesharper)
This PR enables support for IAsyncDisposable ONLY for netcoreapp3.1 and above
Bumped to 6.6.1 (09/19/2022) #575 (seesharper)
IAsyncDisposable Support? (09/19/2022) #560 (Mike-E-angelo)Disable nullable explicitly (09/12/2022) #572 ( Pliner )
Disable nullable explicitly (09/12/2022) #572 (Pliner)
Hey,
We use LightInject(a source code package) as a built-in container for EasyNetQ.
We started a migration to Nullable Reference Types recently and observed build warnings because LightInject doesn't support them(and this is fine).
Could you consider adding #nullable disable pragma? It looks like the simplest way how these warnings could be suppressed.
Anyway, thanks for LightInject 🚀
Asyncdisposable (09/12/2022) #573 (seesharper)
This PR adds support for IAsyncDisposable
Use UnderlyingSystemType for MakeGenericMethod (09/09/2022) #571 ( seesharper )
Use UnderlyingSystemType for MakeGenericMethod (09/09/2022) #571 (seesharper)
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Your coding agent can read these notes before it upgrades. Set up the MCP server →