DelegateFactory 1.0.0
dotnet add package DelegateFactory --version 1.0.0
NuGet\Install-Package DelegateFactory -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DelegateFactory" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DelegateFactory" Version="1.0.0" />
<PackageReference Include="DelegateFactory" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DelegateFactory --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DelegateFactory, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DelegateFactory@1.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DelegateFactory&version=1.0.0
#tool nuget:?package=DelegateFactory&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
About
Supports dependency injection to delegates by injecting arguments of a given delegate with services from an IServiceProvider.
DelegateFactory
was inspired by ASP.Net RequestDelegateFactory
and provides a similar service like this outside of the
specialized scope of web ser ver development.
Key Features
- Static factory method receives a
Delegate
instance and anIServiceProvider
creates a new delegate with injected arguments. - Factory instance can be added to and retrieved from a an
IServiceProvider
as a service itself, ijectin to delegate from thatIServiceProvider
.
How to Use
Use DelegateFactory
like ActivatorUtilities
and inject to delegate with the static factory method:
using DelegateFactory;
var serviceProvider = new ServiceCollection().AddSingleton<IDependency,Dependency>().BuildServiceProvider();
void ADelegateImplementation(int number, IDependency dep) {...}
// IDependency will be injected, the delegate argument of type int remains
var injectedDelegate = DelegateFactory.Apply<Action<int>>(ADelegateImplementation, serviceProvider);
injectedDelegate(1);
Add DelegateFactory
to the service collection and retrieve it as a service:
using DelegateFactory;
var serviceProvider = new ServiceCollection()
.AddSingleton<IDependency,Dependency>()
.AddSingleton<DelegateFactory>()
.BuildServiceProvider();
int ADelegateImplementation(int number, IDependency dep) {..};
// IDependency will be injected, the delegate argument and return value of type int remains
var injectedDelegate = serviceProvider.GetRequiredService<DelegateFactory>().Apply<Func<int,int>>(ADelegateImplementation);
var result = injectedDelegate(1);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0 | 171 | 8/30/2025 |