zijian666.DI.NamedService 1.1.3-beta

This is a prerelease version of zijian666.DI.NamedService.
dotnet add package zijian666.DI.NamedService --version 1.1.3-beta                
NuGet\Install-Package zijian666.DI.NamedService -Version 1.1.3-beta                
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="zijian666.DI.NamedService" Version="1.1.3-beta" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add zijian666.DI.NamedService --version 1.1.3-beta                
#r "nuget: zijian666.DI.NamedService, 1.1.3-beta"                
#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 zijian666.DI.NamedService as a Cake Addin
#addin nuget:?package=zijian666.DI.NamedService&version=1.1.3-beta&prerelease

// Install zijian666.DI.NamedService as a Cake Tool
#tool nuget:?package=zijian666.DI.NamedService&version=1.1.3-beta&prerelease                

<span id="feature3">NamedService命名服务</span>

可为注册服务命名

Install-Package zijian666.DI.NamedService

命名普通服务

var p = new ServiceCollection()
            .AddNamedSingleton("你的名字", "zijian666") // 注册命名服务
            .BuildServiceProvider();

Assert.AreEqual(p.GetNamedService<string>("你的名字"), "zijian666");  // 获取命名服务
Assert.AreEqual(p.GetNamedService<object>("你的名字"), "zijian666");
Assert.AreEqual(p.GetNamedServices<string>("你的名字").FirstOrDefault(), "zijian666");
Assert.IsNull(p.GetNamedService<string>("我的名字"));

命名委托服务

注册的服务类型与使用的服务类型可以不同, 只要兼容即可

var p = new ServiceCollection()
            .AddNamedDelegate("委托", (Func<object, string>)(x => x + "_123")) // 注册命名委托
            .BuildServiceProvider();

var func1 = p.GetNamedDelegate<Func<object, string>>("委托");  // 获取命名委托
Assert.IsNotNull(func1);
Assert.AreEqual(func1("111"), "111_123");

var func2 = p.GetNamedDelegate<Func<string, object>>("委托");

Assert.IsNotNull(func2);
Assert.AreEqual(func2("111"), "111_123");
Product 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 was computed.  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.

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.1.3-beta 63 9/18/2024
1.1.0.15-beta 86 6/24/2024
1.0.7 690 4/7/2023
1.0.6 892 6/10/2022
1.0.4 867 6/9/2022
1.0.0 1,030 3/29/2021

UPLOGS.md