NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
NuGet
NuGet, #2225 most downloaded on NuGet
An ultra lightweight Inversion of Control container for the .Net framework. See LightInject.Source for the source distribution.
Latest stable
7.1.1
Last release 1 months ago
30 Sep 2026
Release timing varies
gaps range from 8 days to 1.5 years
Most releases are documented
notes for 38 of the last 60 stable releases
10 versions withdrawn
withdrawn after publishing
127 years old
102 releases · first in 1900
Drag across the ruler to compare, or tap a release to open it.
Synchronize CanGetInstance with delegate creation (09/25/2026) [\#616](https://github.com/seesharper/LightInject/pull/616) ([seesharper](https://githu
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
Your coding agent can read these notes before it upgrades. Set up the MCP server →
Align keyed service tests with MS.DI spec and fix AnyKey enumeration (05/21/2026) [\#613](https://github.com/seesharper/LightInject/pull/613) ([seesha
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](https://github.com/seesharper/LightInject/pull/607) ([kemsky](https://gith
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](https://github.com/seesharper/LightInject/pull/603) ([seesharper](https://github.com/seesharper))
Removed unused usings (11/19/2024) #603 (seesharper)
Bump version (11/19/2024) #604 (seesharper)
Master (08/12/2023) [\#591](https://github.com/seesharper/LightInject/pull/591) ([oliverscode](https://github.com/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](https://github.com/seesharper/LightInject/pull/584) ([haavamoa](https://github.com/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](https://github.com/seesharper/LightInject/pull/583) ([seesharper](https://gith
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](https://github.com/seesharper/LightInject/pull/576) ([seeshar
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](https://github.com/seesharper/LightInject/pull/574) ([seesharper](h
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](https://github.com/seesharper/LightInject/pull/572) ([Pliner](https://github.com/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).
<img width="1148" alt="image" src="https://user-images.githubusercontent.com/664889/189486436-d6a3e2f1-8f38-4ed6-99f1-0971d37ad7dc.png">
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](https://github.com/seesharper/LightInject/pull/571) ([seesharper](https://github.c
Use UnderlyingSystemType for MakeGenericMethod (09/09/2022) #571 (seesharper)
https://github.com/khellang/Scrutor/issues/175
Updated a ServiceContainer constructor to include the OptimizeForLarg… (08/24/2022) [\#570](https://github.com/seesharper/LightInject/pull/570) ([sirp
Updated a ServiceContainer constructor to include the OptimizeForLarg… (08/24/2022) #570 (sirphilliptubell)
Updated a ServiceContainer constructor to include the OptimizeForLargeObjectGraphs setting + version bump
#561
Move til ILVerifier and set NETSTANDARD2.0 as the minimum requirement (08/11/2022) [\#564](https://github.com/seesharper/LightInject/pull/564) ([seesh
Move til ILVerifier and set NETSTANDARD2.0 as the minimum requirement (08/11/2022) #564 (seesharper)
Use value tuples for the key instead of Tuple to safe allocations (07/24/2022) #566 (danielmarbach)
Feature/optimize for large object graphs (transients) (08/16/2022) #567 (seesharper)
This PR adds a new option called OptimizeForLargeObjectGraphs that favors objects graphs with a large number of transient services.
Bumped version to 6.5.0 (08/16/2022) #568 (seesharper)
Bugfix - Dispose singletons in the correct order (2/7/2022) [\#557](https://github.com/seesharper/LightInject/pull/557) ([seesharper](https://github.c
Bugfix - Dispose singletons in the correct order (2/7/2022) #557 (seesharper)
This PR fixes #556 Update appveyor image (2/7/2022) #562 (seesharper)
Fixed NuGet API Key (2/8/2022) #563 (seesharper)
Bugfix/initializer (10/19/2020) [\#547](https://github.com/seesharper/LightInject/pull/547) ([seesharper](https://github.com/seesharper))
Bugfix/initializer (10/19/2020) #547 (seesharper)
This PR fixes a potential bug where we didn't pass the current scope to the Initialize method.
Also added a new Initialize overload that filters initialization by the TService generic argument.
Bugfix/execute override only once (10/16/2020) [\#546](https://github.com/seesharper/LightInject/pull/546) ([seesharper](https://github.com/seesharper
Bugfix/execute override only once (10/16/2020) #546 (seesharper)
This PR ensures that service overrides are executed only once. This is really important since we can choose to alter the lifetime of a registration.
Corrected order of parameters (6/30/2020) [\#533](https://github.com/seesharper/LightInject/pull/533) ([Illedan](https://github.com/Illedan))
Corrected order of parameters (6/30/2020) #533 (Illedan)
Fixes a simple typo in the Readme. Fix code styles in readme (8/20/2020) #536 (rstm-sf)
Hello!
Fix code highlighting in this
Also, whitespace and long method parameters were fixed to make it more readable Non-closing singleton lifetime (9/17/2020) #540 (seesharper)
This PR removes the last pieces that actually closes over a scope.
Also moved to Coverlet.Collections instead of Coverlet.MsBuild for code coverage Bugfix release notes (9/18/2020) #541 (seesharper)
Allow passing a composition root instance to RegisterFrom (9/22/2020) #542 (seesharper)
This PR adds support for passing an composition root instance to RegisterFrom
Feature override extensions (9/22/2020) #543 (seesharper)
This PR adds a couple over Override overloads that makes it easier to register service overrides.
Removed explicit 2.1 install in build script (9/23/2020) #544 (seesharper)
Skip explicit .Net Core 2.1 install in build script
Remove dependency on System.ValueTuple (6/18/2020) [\#532](https://github.com/seesharper/LightInject/pull/532) ([seesharper](https://github.com/seesha
Remove dependency on System.ValueTuple (6/18/2020) #532 (seesharper)
This PR removes the dependency on System.ValueTuple
Update readme.md (4/6/2020) [\#528](https://github.com/seesharper/LightInject/pull/528) ([DanielKOcean](https://github.com/DanielKOcean))
Update readme.md (4/6/2020) #528 (DanielKOcean)
Pass scope to decorator factory delegate (5/12/2020) #530 (seesharper)
This PR ensures that we pass the scope (IServiceFactory) to decorator factory delegates
Fixed a bug where we missed default interface args (3/9/2020) [\#527](https://github.com/seesharper/LightInject/pull/527) ([seesharper](https://github
Fixed a bug where we missed default interface args (3/9/2020) #527 (seesharper)
Use constructor overload instead of optional parameter (3/2/2020) [\#525](https://github.com/seesharper/LightInject/pull/525) ([seesharper](https://gi
Use constructor overload instead of optional parameter (3/2/2020) #525 (seesharper)
Fixed missing semicolon in IEnumerable Example in readme (2/12/2020) [\#522](https://github.com/seesharper/LightInject/pull/522) ([andmos](https://git
Fixed missing semicolon in IEnumerable Example in readme (2/12/2020) #522 (andmos)
Just a quick little thing, noticed a missing ; in the IEnumerable example.
Optional Arguments (2/26/2020) #523 (seesharper)
This PR adds support for optional arguments if the ContainerOptions.EnableOptionalArguments property is set to true. The default is false.
Bugfix/avl tree rotation (2/11/2020) [\#521](https://github.com/seesharper/LightInject/pull/521) ([seesharper](https://github.com/seesharper))
Bugfix/avl tree rotation (2/11/2020) #521 (seesharper)
This PR fixes a bug we discovered in
https://github.com/seesharper/LightInject.Microsoft.AspNetCore.Hosting/issues/54
The error was caused by an issue with rotating the AVL tree.
Added LifeSpanAttribute (10/16/2019) [\#514](https://github.com/seesharper/LightInject/pull/514) ([seesharper](https://github.com/seesharper))
Added LifeSpanAttribute (10/16/2019) #514 (seesharper)
This PR adds the LifeSpanAttribute that makes it possible to indicate the lifespan of a given lifetime. We will use this information later on for validation purposes such as captive dependencies
Added better docs around scoping (8/29/2019) [\#501](https://github.com/seesharper/LightInject/pull/501) ([seesharper](https://github.com/seesharper))
Added better docs around scoping (8/29/2019) #501 (seesharper)
Added a buy me a coffee link (8/29/2019) #502 (seesharper)
Feature/enable current scope (9/1/2019) #504 (seesharper)
This PR allows the container NOT to maintain the current scope. For instance in AspNet.Core, services are always requested directly from the scope and maintaining a current scopes is just unnecessary overhead.
Performance improvements for scoped/tracked services (9/12/2019) #505 (seesharper)
This PR introduces a few performance improvements when requesting services that requires a scope.
Also added support for disabling the "current scope" through ContainerOptions.EnableCurrentScope
Added support for configure action (9/12/2019) #506 (seesharper)
This PR adds support for configuring the ContainerOptions using a delegate.
var container = new ServiceContainer(o => o.EnablePropertyInjection = false);
Requested by @haavamoa 😎 Document EnableCurrentScope (9/12/2019) #507 (seesharper)
Use ContainerOptions.Default (9/12/2019) #508 (seesharper)
This PR fixes a bug introduced in #506 where we did not respect ContainerOptions.Default
Thanks to @haavamoa for spotting the error Fixes #476 (9/12/2019) #509 (seesharper)
This PR fixes #476 by not passing the emitters and making sure that we register all available services.
Updated an xmldoc typo (7/12/2019) [\#491](https://github.com/seesharper/LightInject/pull/491) ([Hammerstad](https://github.com/Hammerstad))
Updated an xmldoc typo (7/12/2019) #491 (Hammerstad)
Updated a typo in the xmldoc for ContainerOptions.LogFactory Update version (8/2/2019) #493 (danielmarbach)
Given https://github.com/seesharper/LightInject/blob/master/src/LightInject/LightInject.csproj#L5 should the version also be reflected in the source file? Added Scope Performance tests (8/11/2019) #498 (seesharper)
Flow the scope when possible (8/28/2019) #500 (seesharper)
This PR adds support for "flowing" the scope whenever possible.
This means that we pass the scope that requested a service throughout the object graph.
Example
container.RegisterScoped<IFoo>(factory => new Foo());
The factory passed into the factory delegate is an IServiceFactory and this used to always be the ServiceContainer implementing the IServiceFactory interface. What is changed is that we now pass in the Scope which also implements IServiceFactory.
When LightInject was born, there was always this notion of a current scope. An ambient context that can be used to access the current scope. It supports scenarios like
using (container.BeginScope())
{
var foo = container.GetInstance<IFoo>();
}
The way this works is that when IFoo is requested we ask for the current scope and use that scope for resolving the instance.
Then we introduced support for getting a service directly from a scope.
using (var outerScope = container.BeginScope())
{
using(var innerScope = container.BeginScope())
{
var outerFoo = outerScope.GetInstance<IFoo>();
var innerFoo = innerScope.GetInstance<IFoo>();
}
}
The way that this used to work was that we swapped the current scope with the scope from which the service was requested. After we resolved the service we restored the current scope to the previous current scope.
This was problematic in a number of ways.
AsyncLocal<T>.Func<T> and Lazy<T> that always relied on the current scope could end up using the "wrong" scope if someone or something started a new scope using container.BeginScope which in turn sets the current scope to new newly created scope.Instead of always relying on the current scope, we pass the scope throughout the code that is generated to resolve an instance. One important aspect of this is that we do this with as little breakage as possible. That means that of the service is directly requested from the scope, we pass that scope without messing with the current scope. If we request a service from the container, the current scope will be used as before.
It should be noted that requesting service directly from the scope is the preferred way with regards to performance and correctness. We will not remove support for the ambient scope, but we might emit a warning log message in the future.
Remove childscope test (5/15/2019) [\#486](https://github.com/seesharper/LightInject/pull/486) ([seesharper](https://github.com/seesharper))
Remove childscope test (5/15/2019) #486 (seesharper)
We used to throw an exception when a parent scope was disposed before all child scopes were disposed. This turns out to be a problem in AspNet Core specially when using HttpClientFactory.
This check has been in LightInject since the beginning, but there is no danger in removing this check as long as all scoped are eventually disposed.
Bumped to version 5.5.0 (5/16/2019) #487 (seesharper)
Added unit testing doc (1/19/2019) [\#469](https://github.com/seesharper/LightInject/pull/469) ([seesharper](https://github.com/seesharper))
Added unit testing doc (1/19/2019) #469 (seesharper)
Adds docs regarding unit testing Added missing register concrete service overloads (1/24/2019) #470 (seesharper)
Bugfix/ignorecase opengenerics (1/24/2019) #471 (seesharper)
This fixes a bug where name open generic services was not treated as case-insensitive services. Added support for SDK style source packages (1/25/2019) #472 (seesharper)
Fixes #457 and now adds support for a SDK style source package.
Note that this also removed the support for source packages in legacy projects using the "old" csproj format.
Feature/variance filter (12/10/2018) [\#463](https://github.com/seesharper/LightInject/pull/463) ([seesharper](https://github.com/seesharper))
Feature/variance filter (12/10/2018) #463 (seesharper)
Adds support for setting a variance filter that determines if variance should be applied for a given IEnumerable<T> service
fixed Lazy Decorators header (10/4/2018) [\#455](https://github.com/seesharper/LightInject/pull/455) ([dadhi](https://github.com/dadhi))
fixed Lazy Decorators header (10/4/2018) #455 (dadhi)
SourceLink and XML comments (11/10/2018) #460 (seesharper)
Adds support for sourcelink enabled pdb file and xml comments in the NuGet package.
Lazy with named services (9/12/2018) [\#443](https://github.com/seesharper/LightInject/pull/443) ([seesharper](https://github.com/seesharper))
Lazy<T> with named services (9/12/2018) #443 (seesharper)
Fixes #427 by using the service name when resolving the underlying value for Lazy<T>
Add convenience register extension methods (9/13/2018) #446 (seesharper)
Adds support for RegisterTransient, RegisterScoped and RegisterSingleton .
This means that we can do
container.RegisterScoped<IFoo, Foo>();
instead of
container.Register<IFoo, Foo>(new PerScopeLifetime());
Default to PerLogicalCallContextScopeManagerProvider (9/27/2018) #450 (0xced)
On target frameworks where it’s available, default to using PerLogicalCallContextScopeManagerProvider instead of PerThreadScopeManagerProvider.
See also #153. Added non-generic object factory (9/28/2018) #453 (seesharper)
version 5.2.0 (9/28/2018) #454 (seesharper)
Bugfix/opengeneric (9/10/2018) [\#442](https://github.com/seesharper/LightInject/pull/442) ([seesharper](https://github.com/seesharper))
Bugfix/opengeneric (9/10/2018) #442 (seesharper)
Fixes a bug where resolving open generic types passed an empty list of services to DefaultServiceSelector
Support named dependency convention when using custom ServiceSelector (8/24/2018) [\#438](https://github.com/seesharper/LightInject/pull/438) ([henrih
Support named dependency convention when using custom ServiceSelector (8/24/2018) #438 (henrihs)
Try to resolve dependencies by using parameter names when several mathcing services are registered. When using a custom DefaultServiceSelector, this behaviour is broken.
Feature/netstandard2.0 (8/24/2018) #439 (seesharper)
Adds netstandard2.0 as one of target frameworks Pr438 (9/7/2018) #440 (seesharper)
This fixes a bug that caused the fallback to dependency name (constructor or property) to fail when using a DefaultServiceSelector that always resolves a default service.
Set version to 5.1.9 (9/7/2018) #441 (seesharper)
Sets the correct version 5.1.9
Fully implement the Clone method. Fixes #396 (8/23/2018) [\#437](https://github.com/seesharper/LightInject/pull/437) ([seesharper](https://github.com/
Fully implement the Clone method. Fixes #396 (8/23/2018) #437 (seesharper)
Performance/reuse delegates (8/21/2018) [\#436](https://github.com/seesharper/LightInject/pull/436) ([seesharper](https://github.com/seesharper))
Performance/reuse delegates (8/21/2018) #436 (seesharper)
Improves memory usage by reusing the generated GetInstanceDelegate.
Thanks to @leandro86 for coming up with such a simple and effective solution. 👍
Bugfix/named collections (8/7/2018) [\#433](https://github.com/seesharper/LightInject/pull/433) ([seesharper](https://github.com/seesharper))
Bugfix/named collections (8/7/2018) #433 (seesharper)
Fixes a bug that caused named collections to yields an empty result.
https://github.com/seesharper/LightInject.Microsoft.DependencyInjection/issues/27
Fixed assembly file version (7/5/2018) [\#425](https://github.com/seesharper/LightInject/pull/425) ([seesharper](https://github.com/seesharper))
Fixed assembly file version (7/5/2018) #425 (seesharper)
Sets the assembly file version. Enabled tests (7/5/2018) #426 (seesharper)
Enabled tests again
Tests/decorators (5/17/2018) [\#418](https://github.com/seesharper/LightInject/pull/418) ([seesharper](https://github.com/seesharper))
Tests/decorators (5/17/2018) #418 (seesharper)
Added a new decorator test and use new C# language features across the code base. Better support for Microsoft.Extensions.DependencyInjection (6/23/2018) #420 (seesharper)
This PR adds a couple of changes related to the Microsoft.Extensions.DependencyInjection integration.
ContainerOptions.DefaultServiceSelectornetcoreapp2.0 target so that we can use System.Reflection.Emit.LightWeight on .Net CoreInclude pull request body in release notes (6/24/2018) #421 (seesharper)
Ensure that we include the pull request body when generating release notes. Build/artifacts (6/24/2018) #422 (seesharper)
Added Artifacts folder to .gitignore file
Remove zero width space... (26.03.2018) [\#410](https://github.com/seesharper/LightInject/pull/410) ([kreediam](https://github.com/kreediam))
Remove zero width space... (26.03.2018) #410 (kreediam)
(\u200b) which breaks code formatting Feature/Compilation (08.05.2018) #412 (seesharper)
This PR adds support for compiling delegates up front.
Initial docs
LightInject uses dynamic code compilation either in the form of System.Reflection.Emit or compiled expression trees. When a service is requested from the container, the code needed for creating the service instance is generated and compiled and a delegate for that code is stored for lookup later on so that we only compile it once. These delegates are stored in an AVL tree that ensures maximal performance when looking up a delegate for a given service type. If fact, looking up these delegates is what sets the top performing containers apart. Most high performance container emits approximately the same code, but the approach to storing these delegates may differ.
LightInject provides lock-free service lookup meaning that no locks are involved for getting a service instance after its initial generation and compilation. The only time LightInject actually creates a lock is when generating the code for a given service. That does however mean a potential lock contention problem when many concurrent requests asks for services for the first time.
LightInject deals with this potential problem by providing an API for compilation typically used when an application starts.
The following example shows how to compile all registered services.
container.Compile();
One thing to be aware of is that not all services are backed by its own delegate.
Consider the following service:
public class Foo
{
public Foo(Bar bar)
{
Bar = bar;
}
}
Registered and resolved like this:
container.Register<Foo>();
container.Register<Bar>();
var foo = container.GetInstance<Foo>();
In this case we only create a delegate for resolving Foo since that is the only service that is directly requested from the container. The code for creating the Bar instance is embedded inside the code for creating the Foo instance and hence there is only one delegate created.
We call Foo a root service since it is directly requested from the container.
In fact lets just have a look at the IL generated for creating the Foo instance.
newobj Void .ctor() // Bar
newobj Void .ctor(LightInject.SampleLibrary.IBar) //Foo
What happens here is that a new instance of Bar is created and pushed onto the stack and then we create the Foo instance. This is the code that the delegate for Foo points to.
The reason for such a relatively detailed explanation is to illustrate that we don't always create a delegate for a given service and by simply doing a container.Compile() we might create a lot of delegates that is never actually executed. Probably no big deal as long as we don't have tens of thousands of services, but just something to be aware of.
LightInject does not attempt to identify root services as that would be very difficult for various reasons.
We can instead use a predicate when compiling services up front.
container.Compile(sr => sr.ServiceType == typeof(Foo));
LightInject cannot compile open generic services since the actual generic arguments are not known at "compile" time.
We can however specify the generic arguments like this:
container.Compile<Foo<int>>()
LightInject will create a log entry every time a new delegate is created so that information can be used to identify root services that could be compiled up front. In addition to this, a log entry (warning) is also created when trying to compile an open generic service up front.
Use instance lock instead of static lock (Scope) (08.05.2018) #413 (seesharper)
This PR addresses #411 and changes the lock used inside the Scope class from a static lock to an instance lock
Bumped to 5.1.3 for release (08.05.2018) #414 (seesharper)
This PR bumps the version to 5.1.3
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
One column per quarter.