Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mustaddon/lazydependencyinjection
Lazy injection for Microsoft.Extensions.DependencyInjection. Decorates registered services with lazy proxies that instantiate the original service only after the first method or property call. Intended to prevent the creation of unused injected dependencies.
https://github.com/mustaddon/lazydependencyinjection
dependency-injection dispatch-proxy lazy-injection lazy-loading lazy-proxy lazy-service proxy-pattern service-collection service-provider virtual-proxy
Last synced: 28 days ago
JSON representation
Lazy injection for Microsoft.Extensions.DependencyInjection. Decorates registered services with lazy proxies that instantiate the original service only after the first method or property call. Intended to prevent the creation of unused injected dependencies.
- Host: GitHub
- URL: https://github.com/mustaddon/lazydependencyinjection
- Owner: mustaddon
- License: mit
- Created: 2024-11-10T12:21:56.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-11-27T06:36:06.000Z (2 months ago)
- Last Synced: 2024-12-27T14:45:48.239Z (about 1 month ago)
- Topics: dependency-injection, dispatch-proxy, lazy-injection, lazy-loading, lazy-proxy, lazy-service, proxy-pattern, service-collection, service-provider, virtual-proxy
- Language: C#
- Homepage:
- Size: 642 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LazyDependencyInjection [![NuGet version](https://badge.fury.io/nu/LazyDependencyInjection.svg?105)](http://badge.fury.io/nu/LazyDependencyInjection)
Lazy injection for Microsoft.Extensions.DependencyInjection using the [Proxy pattern](https://en.wikipedia.org/wiki/Proxy_pattern).\
Decorates registered services with lazy proxies that instantiate the original service only after the first method or property call.\
Intended to prevent the creation of unused injected dependencies.### Example
```C#
using LazyDependencyInjection;var services = new ServiceCollection()
.AddTransient()
.AddTransient()
.AddTransient()
.AddTransient()
// DEFAULT: Adds for any service that has dependencies
// and injections into other services with multiple methods and dependencies
.AddLazyProxy()
// OR: Default analog with additional assembly condition for services
.AddLazyProxy(Assembly.GetExecutingAssembly())// OR: Adds only for specified services
.AddLazyProxy(typeof(IExampleService1), typeof(IExampleService2))
// OR: Adds with your custom filter
.AddLazyProxy(x => !x.Descriptor.IsKeyedService && x.Descriptor.HasDependenciesCountGreaterThan(0))// OR: Adds for any service that has dependencies and injections into specific services
.AddLazyProxy(ServiceFilters.HasDependencies()
.And(ServiceFilters.IsInjectedTo(typeof(ServiceWithManyUnusedDeps)))).BuildServiceProvider();
```[Program.cs](https://github.com/mustaddon/LazyDependencyInjection/blob/main/Example/Program.cs)
### Concept
[![](https://raw.githubusercontent.com/mustaddon/LazyDependencyInjection/master/dgrm.png)](https://app.dgrm.net/?u=https://raw.githubusercontent.com/mustaddon/LazyDependencyInjection/master/dgrm.png)