Smart.Inject 3.0.1

dotnet add package Smart.Inject --version 3.0.1                
NuGet\Install-Package Smart.Inject -Version 3.0.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="Smart.Inject" Version="3.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Smart.Inject --version 3.0.1                
#r "nuget: Smart.Inject, 3.0.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 Smart.Inject as a Cake Addin
#addin nuget:?package=Smart.Inject&version=3.0.1

// Install Smart.Inject as a Cake Tool
#tool nuget:?package=Smart.Inject&version=3.0.1                

Smart.Inject

NuGet
专为.NET 6/8/9设计的智能依赖注入框架,能扫描程序集并自动注册自定义服务,可对程序集的服务进行个性化配置

核心特性

  • 零配置自动注册:自动扫描程序集注册服务
  • 生命周期管理:通过[ServiceOf*]特性标记Singleton/Scoped/Transient
  • 智能过滤[IgnoreInject]排除特定类型
  • 模块化配置IServiceConfigure实现按程序集配置
  • 策略定制:支持6种服务注册策略(All/Default/OnlyBaseClass等)

快速安装

bash
dotnet add package Smart.Inject

基础用法

csharp
// 启动配置
services.AddSmartInject()
.AddAssembly(Assembly.GetExecutingAssembly())
.ScanCustomizedServices(configuration);

// 自动注册示例
[ServiceOfScoped(InjectScheme.OnlyInterfaces)]
public class OrderService : IOrderService { /* 自动注册为IOrderService */ }

// 排除注册示例
[IgnoreInject]
public class InternalService : IHostedService { /* 不注册 */ }

高级配置

csharp
// 自定义注册策略
[Service(Lifetime = ServiceLifetime.Singleton,Scheme = InjectScheme.Customized,ServiceType = new[] { typeof(ILogger) })]
public class CustomLogger : ILogger { /* 显式注册 */ }
// 模块化配置
public class AuthConfigure : IServiceConfigure
{
public void Configure(IServiceCollection services, IConfiguration config)
{
services.AddJwtAuth(config);
}
}

最佳实践

  • 使用InjectScheme.OnlyInterfaces强制面向接口编程
  • 在类库中实现IServiceConfigure实现自治配置

Developed by zenglei

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 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.  net9.0 is compatible.  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
3.0.1 29 2/15/2025
3.0.0 29 2/15/2025
2.0.3 34 2/13/2025
2.0.2 67 2/9/2025
2.0.1 105 12/7/2024
2.0.0 88 11/26/2024
1.0.0.5 106 10/9/2024
1.0.0.4 99 9/25/2024
1.0.0.3 104 9/24/2024
1.0.0.2 108 9/20/2024
1.0.0.1 95 9/20/2024
1.0.0 131 9/8/2024