EasilyNET.AutoDependencyInjection 2.1.9

There is a newer version of this package available.
See the version list below for details.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package EasilyNET.AutoDependencyInjection --version 2.1.9
                    
NuGet\Install-Package EasilyNET.AutoDependencyInjection -Version 2.1.9
                    
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="EasilyNET.AutoDependencyInjection" Version="2.1.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EasilyNET.AutoDependencyInjection" Version="2.1.9" />
                    
Directory.Packages.props
<PackageReference Include="EasilyNET.AutoDependencyInjection" />
                    
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 EasilyNET.AutoDependencyInjection --version 2.1.9
                    
#r "nuget: EasilyNET.AutoDependencyInjection, 2.1.9"
                    
#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=EasilyNET.AutoDependencyInjection&version=2.1.9
                    
Install as a Cake Addin
#tool nuget:?package=EasilyNET.AutoDependencyInjection&version=2.1.9
                    
Install as a Cake Tool
EasilyNET.AutoDependencyInjection

自动注入模块,参考 ABP 的代码实现.

如何使用
  • 使用 Nuget 包管理工具添加依赖包 EasilyNET.AutoDependencyInjection
  • a.使用特性注入服务
[DependencyInjection(ServiceLifetime.Singleton, AddSelf = true)]
public class XXXService : IXXXService
{
    // TODO: do something
    Console.WriteLine("使用特性注入服务");
    ...
}
  • b.使用接口的方式,继承 IScopedDependency, ISingletonDependency, ITransientDependency
/// <summary>
/// 测试模块
/// </summary>
public class MyTestModule : ITest, IScopedDependency
{
    /// <summary>
    /// Show
    /// </summary>
    public void Show()
    {
        Console.WriteLine("Test");
    }
}

/// <summary>
/// 测试
/// </summary>
//[IgnoreDependency]
public interface ITest
{
    /// <summary>
    /// Show函数
    /// </summary>
    void Show();
}

// 在其他地方获取服务,并执行方法
var test = context.Services.GetService<MyTestModule>();
test?.Show();
...
  • 3.继承 AppModule 类,然后显示加入到 AppWebModule 配置中
  • Step1.创建 CorsModule.cs
// 这里以跨域服务注册为例
/// <summary>
/// 配置跨域服务及中间件
/// </summary>
public class CorsModule : AppModule
{
    /// <summary>
    /// 注册和配置服务
    /// </summary>
    /// <param name="context"></param>
    public override void ConfigureServices(ConfigureServicesContext context)
    {
        var config = context.Services.GetConfiguration();
        var allow = config["AllowedHosts"] ?? "*";
        _ = context.Services.AddCors(c => c.AddPolicy("AllowedHosts", s => s.WithOrigins(allow.Split(",")).AllowAnyMethod().AllowAnyHeader()));
    }
    /// <summary>
    /// 注册中间件
    /// </summary>
    /// <param name="context"></param>
    public override void ApplicationInitialization(ApplicationContext context)
    {
        var app = context.GetApplicationBuilder();
        _ = app.UseCors("AllowedHosts");
    }
}
  • Step2.创建 AppWebModule.cs
/**
 * 要实现自动注入,一定要在这个地方添加
 */
[DependsOn(
    typeof(DependencyAppModule),
    typeof(CorsModule)
)]
public class AppWebModule : AppModule
{
    /// <summary>
    /// 注册和配置服务
    /// </summary>
    /// <param name="context"></param>
    public override void ConfigureServices(ConfigureServicesContext context)
    {
        base.ConfigureServices(context);
        _ = context.Services.AddHttpContextAccessor();
    }
    /// <summary>
    /// 注册中间件
    /// </summary>
    /// <param name="context"></param>
    public override void ApplicationInitialization(ApplicationContext context)
    {
        base.ApplicationInitialization(context);
        var app = context.GetApplicationBuilder();
        _ = app.UseAuthorization();
        // 这里可添加自己的中间件
    }
}
  • Step3.最后再 Program.cs 中添加如下内容.
// Add services to the container.
// 自动注入服务模块
builder.Services.AddApplication<AppWebModule>();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment()) _ = app.UseDeveloperExceptionPage();

// 添加自动化注入的一些中间件.
app.InitializeApplication();

app.MapControllers();

app.Run();
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.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
4.25.617.153 133 6/17/2025
4.25.616.190 126 6/16/2025
4.25.616.182 121 6/16/2025
4.25.613.111 271 6/13/2025
4.25.609.190 673 6/9/2025
1.5.2 322 5/10/2023 1.5.2 is deprecated because it has critical bugs.
1.5.1 317 5/10/2023 1.5.1 is deprecated because it has critical bugs.
1.5.0 364 5/6/2023 1.5.0 is deprecated because it has critical bugs.
1.4.0 328 5/5/2023 1.4.0 is deprecated because it has critical bugs.
1.3.9 329 4/23/2023 1.3.9 is deprecated because it has critical bugs.
1.3.8.6 313 4/23/2023 1.3.8.6 is deprecated because it has critical bugs.
1.3.8.5 319 4/21/2023 1.3.8.5 is deprecated because it has critical bugs.
1.3.8.1 386 4/12/2023 1.3.8.1 is deprecated because it has critical bugs.
1.3.8 330 4/11/2023 1.3.8 is deprecated because it has critical bugs.
1.3.7 355 4/9/2023 1.3.7 is deprecated because it has critical bugs.
1.3.6.3 411 4/1/2023 1.3.6.3 is deprecated because it has critical bugs.
1.3.6.2 326 3/31/2023 1.3.6.2 is deprecated because it has critical bugs.
1.3.6.1 327 3/31/2023 1.3.6.1 is deprecated because it has critical bugs.
1.3.6 300 3/31/2023 1.3.6 is deprecated because it has critical bugs.
1.3.5 329 3/30/2023 1.3.5 is deprecated because it has critical bugs.
1.3.4.1 387 3/29/2023 1.3.4.1 is deprecated because it has critical bugs.
1.3.4 335 3/28/2023 1.3.4 is deprecated because it has critical bugs.
1.3.3 310 3/28/2023 1.3.3 is deprecated because it has critical bugs.
1.3.2 341 3/26/2023 1.3.2 is deprecated because it has critical bugs.
1.3.1 396 3/22/2023 1.3.1 is deprecated because it has critical bugs.
1.3.0 332 3/21/2023 1.3.0 is deprecated because it has critical bugs.
1.2.0 321 3/21/2023 1.2.0 is deprecated because it has critical bugs.
1.1.0 335 3/17/2023 1.1.0 is deprecated because it has critical bugs.
1.0.9 331 3/15/2023 1.0.9 is deprecated because it has critical bugs.
1.0.8 334 3/15/2023 1.0.8 is deprecated because it has critical bugs.
1.0.7 314 3/15/2023 1.0.7 is deprecated because it has critical bugs.
1.0.6 334 3/13/2023 1.0.6 is deprecated because it has critical bugs.
1.0.5 338 3/13/2023 1.0.5 is deprecated because it has critical bugs.
1.0.4 315 3/13/2023 1.0.4 is deprecated because it has critical bugs.
1.0.3 398 2/26/2023 1.0.3 is deprecated because it has critical bugs.
1.0.2 321 2/26/2023 1.0.2 is deprecated because it has critical bugs.
1.0.1 339 2/23/2023 1.0.1 is deprecated because it has critical bugs.