More.Extensions.DependencyInjection.Keyed
1.0.0-preview.1
This is a prerelease version of More.Extensions.DependencyInjection.Keyed.
dotnet add package More.Extensions.DependencyInjection.Keyed --version 1.0.0-preview.1
NuGet\Install-Package More.Extensions.DependencyInjection.Keyed -Version 1.0.0-preview.1
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="More.Extensions.DependencyInjection.Keyed" Version="1.0.0-preview.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add More.Extensions.DependencyInjection.Keyed --version 1.0.0-preview.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: More.Extensions.DependencyInjection.Keyed, 1.0.0-preview.1"
#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.
// Install More.Extensions.DependencyInjection.Keyed as a Cake Addin #addin nuget:?package=More.Extensions.DependencyInjection.Keyed&version=1.0.0-preview.1&prerelease // Install More.Extensions.DependencyInjection.Keyed as a Cake Tool #tool nuget:?package=More.Extensions.DependencyInjection.Keyed&version=1.0.0-preview.1&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Provides extensions for creating keyed services using a Type
for a key with Microsoft.Extensions.DependencyInjection.
The following containers are supported with this package alone:
- Default
- Autofac
- LightInject
- Unity
The following containers are supported via an additional package:
Commonly Used Types
- Extensions.DependencyInjection.IKeyed<TKey,TService>
- More.Extensions.DependencyInjection.ServiceProviderExtensions
- More.Extensions.DependencyInjection.KeyedServiceCollectionExtensions
Example
public interface IThing
{
string ToString();
}
public abstract class ThingBase : IThing
{
protected ThingBase() { }
public override string ToString() => GetType().Name;
}
public sealed class Thing : ThingBase { }
public sealed class KeyedThing : ThingBase { }
public sealed class Thing1 : ThingBase { }
public sealed class Thing2 : ThingBase { }
public sealed class Thing3 : ThingBase { }
public static class Key
{
public sealed class Thingies { }
public sealed class Thing1 { }
public sealed class Thing2 { }
}
public class CatInTheHat
{
public CatInTheHat(
IKeyed<Key.Thing1, IThing> thing1,
IKeyed<Key.Thing2, IThing> thing2)
{
Thing1 = thing1.Value;
Thing2 = thing2.Value;
}
public IThing Thing1 { get; }
public IThing Thing2 { get; }
}
var services = new ServiceCollection();
// keyed types
services.AddSingleton<Key.Thing1, IThing, Thing1>();
services.AddTransient<Key.Thing2, IThing, Thing2>();
// non-keyed type with keyed type dependencies
services.AddSingleton<CatInTheHat>();
// keyed open generics
services.AddTransient(typeof(IGeneric<>), typeof(Generic<>));
services.AddSingleton(typeof(IKeyed<,>), typeof(KeyedOpenGeneric<,>));
// keyed IEnumerable<T>
services.TryAddEnumerable<Key.Thingies, IThing, Thing1>(ServiceLifetime.Transient);
services.TryAddEnumerable<Key.Thingies, IThing, Thing2>(ServiceLifetime.Transient);
services.TryAddEnumerable<Key.Thingies, IThing, Thing3>(ServiceLifetime.Transient);
var provider = services.BuildServiceProvider();
// resolve non-keyed type with keyed type dependencies
var catInTheHat = provider.GetRequiredService<CatInTheHat>();
// resolve keyed, open generic
var openGeneric = provider.GetRequiredService<Key.Thingy, IGeneric<object>>();
// resolve keyed IEnumerable<T>
var thingies = provider.GetServices<Key.Thingies, IThing>();
// related services such as IServiceProviderIsService
var query = provider.GetRequiredService<IServiceProviderIsService>();
var thing1Registered = query.IsService<Key.Thing1, IThing>();
var thing2Registered = query.IsService(typeof(Key.Thing2), typeof(IThing));
Release Notes
https://github.com/commonsensesoftware/more-keyed-services/releases/tag/v1.0.0-preview.1
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
-
net7.0
NuGet packages (5)
Showing the top 5 NuGet packages that depend on More.Extensions.DependencyInjection.Keyed:
Package | Downloads |
---|---|
More.Grace.Extensions.DependencyInjection.Keyed
Package Description |
|
More.DryIoc.Extensions.DependencyInjection.Keyed
Package Description |
|
More.Lamar.Extensions.DependencyInjection.Keyed
Package Description |
|
More.StructureMap.Extensions.DependencyInjection.Keyed
Package Description |
|
More.Stashbox.Extensions.DependencyInjection.Keyed
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0-preview.1 | 267 | 8/12/2023 |