![]() |
VOOZH | about |
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
<PackageReference Include="More.Extensions.DependencyInjection.Keyed" Version="1.0.0-preview.1" />
<PackageVersion Include="More.Extensions.DependencyInjection.Keyed" Version="1.0.0-preview.1" />Directory.Packages.props
<PackageReference Include="More.Extensions.DependencyInjection.Keyed" />Project file
paket add More.Extensions.DependencyInjection.Keyed --version 1.0.0-preview.1
#r "nuget: More.Extensions.DependencyInjection.Keyed, 1.0.0-preview.1"
#:package More.Extensions.DependencyInjection.Keyed@1.0.0-preview.1
#addin nuget:?package=More.Extensions.DependencyInjection.Keyed&version=1.0.0-preview.1&prereleaseInstall as a Cake Addin
#tool nuget:?package=More.Extensions.DependencyInjection.Keyed&version=1.0.0-preview.1&prereleaseInstall as a Cake Tool
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:
The following containers are supported via an additional package:
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));
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 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 is compatible. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 5 NuGet packages that depend on More.Extensions.DependencyInjection.Keyed:
| Package | Downloads |
|---|---|
|
More.Stashbox.Extensions.DependencyInjection.Keyed
Package Description |
|
|
More.DryIoc.Extensions.DependencyInjection.Keyed
Package Description |
|
|
More.Grace.Extensions.DependencyInjection.Keyed
Package Description |
|
|
More.Lamar.Extensions.DependencyInjection.Keyed
Package Description |
|
|
More.StructureMap.Extensions.DependencyInjection.Keyed
Package Description |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-preview.1 | 416 | 8/12/2023 |