EasyInjector.DependencyInjection 1.6.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package EasyInjector.DependencyInjection --version 1.6.0                
NuGet\Install-Package EasyInjector.DependencyInjection -Version 1.6.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="EasyInjector.DependencyInjection" Version="1.6.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EasyInjector.DependencyInjection --version 1.6.0                
#r "nuget: EasyInjector.DependencyInjection, 1.6.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.
// Install EasyInjector.DependencyInjection as a Cake Addin
#addin nuget:?package=EasyInjector.DependencyInjection&version=1.6.0

// Install EasyInjector.DependencyInjection as a Cake Tool
#tool nuget:?package=EasyInjector.DependencyInjection&version=1.6.0                

EasyInjector.DependencyInjection

  • EasyInjector 於 .net core 上 提供一些專用的服務
    • EasyInjector 沒有 .net core版本 而是直接改用內建的 Dependency Injection

額外提供 INamed 作為同類服務有多個實例

  var services = new ServiceCollection();
  services.AddEasyInjector();
  // 註冊服務 定義名稱如何取得實例
  services.AddNamedScoped<IFtpAdminService>((sp, name) => new FtpAdminService(name));

  var provider = services.BuildServiceProvider(true);
  using var scope = provider.CreateScope();
  // 取得本服務 再透過他取得其他實例 by Name
  var srv = scope.ServiceProvider
  	.GetRequiredService<INamed<IFtpAdminService>>()
	.GetByName("Default");

額外提供 IProvider 特定服務的提供者 常用於Scope場合。


	// 某服務的應用情境展示
	public class SomeService : ISomeService {

		readonly IProvider<IFtp> _ftpf;
		readonly IServiceScopeFactory _scopef;

		// 建構式有清楚的描述本服務 有依賴IFtp的關係
		public SomeService(
			IProvider<IFtp> ftpf,
			IServiceScopeFactory scopef)
		{
			_ftpf = ftpf;
			_scopef = scopef;
		}

		// 某些動作才須要實際取得IFtp服務 呼叫完成就釋放
		public void DoSomething() {
			using(var scope = _scopef.CreateScope()) {
				// 這時候才真的產生這個服務
				var ftp = _ftpf.Get(scope);

				ftp.DoSomething();
			}
		}
	}

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.
  • net8.0

    • No dependencies.

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.6.3 110 8/29/2024
1.6.2 109 8/27/2024
1.6.1 114 8/26/2024
1.6.0 103 8/26/2024