zijian666.DI.NamedService 1.3.0

dotnet add package zijian666.DI.NamedService --version 1.3.0
                    
NuGet\Install-Package zijian666.DI.NamedService -Version 1.3.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="zijian666.DI.NamedService" Version="1.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="zijian666.DI.NamedService" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="zijian666.DI.NamedService" />
                    
Project file
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 zijian666.DI.NamedService --version 1.3.0
                    
#r "nuget: zijian666.DI.NamedService, 1.3.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.
#addin nuget:?package=zijian666.DI.NamedService&version=1.3.0
                    
Install zijian666.DI.NamedService as a Cake Addin
#tool nuget:?package=zijian666.DI.NamedService&version=1.3.0
                    
Install zijian666.DI.NamedService as a Cake Tool

<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.  net9.0 was computed.  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. 
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.3.0 133 3/13/2025
1.2.4-beta 81 12/23/2024
1.2.0-beta 66 11/27/2024
1.1.3-beta 76 9/18/2024
1.1.0.15-beta 96 6/24/2024
1.0.7 707 4/7/2023
1.0.6 914 6/10/2022
1.0.4 886 6/9/2022
1.0.0 1,057 3/29/2021

UPLOGS.md