EasilyNET.AutoDependencyInjection 1.9.0-preview2

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

// Install EasilyNET.AutoDependencyInjection as a Cake Tool
#tool nuget:?package=EasilyNET.AutoDependencyInjection&version=1.9.0-preview2&prerelease                
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 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 is compatible.  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 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
4.25.108.182 6 1/8/2025
4.25.108.160 12 1/8/2025
4.25.1.1 91 1/1/2025
3.24.1224.141 77 12/24/2024
3.24.1216.116 101 12/16/2024
3.24.1206.100 94 12/6/2024
3.24.1205.171 101 12/5/2024
3.24.1202.150 91 12/2/2024
3.24.1126.231 97 11/26/2024
3.24.1126.172 91 11/26/2024
3.24.1126.114 86 11/26/2024
3.24.1126.104 84 11/26/2024
3.24.1125.181 79 11/25/2024
3.24.1125.104 92 11/25/2024
3.24.1121.183 89 11/21/2024
3.24.1120.183 93 11/20/2024
3.24.1119.31 89 11/18/2024
3.24.1115.143 79 11/15/2024
3.24.1113.100 102 11/13/2024
3.24.1112.125 84 11/12/2024
3.24.1107.140 99 11/7/2024
3.24.1107.54 85 11/7/2024
3.24.1107.34 87 11/7/2024
3.24.1105.111 90 11/5/2024
3.24.1103.31 96 11/2/2024
3.24.1103 92 11/2/2024
3.24.1031.135 93 10/31/2024
3.24.1031.112 89 10/31/2024
3.24.1031.104 92 10/31/2024
3.24.1029.142 96 10/29/2024
3.24.1025.30 92 10/24/2024
3.24.1022.142 78 10/22/2024
3.24.1018.204 147 10/18/2024
3.24.1018.175 139 10/18/2024
3.24.1018.166 140 10/18/2024
3.24.1018.93 151 10/18/2024
3.24.1017.42 113 10/16/2024
3.24.1016.161 111 10/16/2024
3.24.1015.231 98 10/15/2024
3.24.1015.14 90 10/14/2024
3.24.1012.114 92 10/12/2024
3.24.1009.115 98 10/9/2024
3.24.1008.160 92 10/8/2024
3.24.1008.133 95 10/8/2024
3.24.1007.185 99 10/7/2024
3.24.1003.33 100 10/2/2024
3.24.1002.162 97 10/2/2024
3.24.929.143 93 9/29/2024
3.24.929.141 81 9/29/2024
3.24.929.131 95 9/29/2024
3.24.929.122 99 9/29/2024
3.24.926.184 96 9/26/2024
3.24.926.182 86 9/26/2024
3.24.926.175 92 9/26/2024
3.24.924.160 97 9/24/2024
3.24.924.133 106 9/24/2024
3.24.924.124 91 9/24/2024
3.24.924.10 98 9/23/2024
3.24.924.1 85 9/23/2024
3.24.923.234 88 9/23/2024
3.24.923.232 96 9/23/2024
3.24.923.155 95 9/23/2024
3.24.919.92 109 9/19/2024
3.24.914.125 122 9/14/2024
3.24.914.115 104 9/14/2024
3.24.914.111 105 9/14/2024
3.24.911.95 113 9/11/2024
3.24.908.215 95 9/8/2024
3.24.904.200 108 9/4/2024
3.24.828.163 132 8/28/2024
3.24.820.173 115 8/20/2024
3.24.814.92 135 8/14/2024
3.24.812.115 114 8/12/2024
3.24.802.100 71 8/2/2024
3.24.801.162 86 8/1/2024
3.24.801.160 77 8/1/2024
3.24.801.155 79 8/1/2024
3.24.801.153 123 8/1/2024
3.24.730.164 80 7/30/2024
3.24.730.91 80 7/30/2024
3.24.724.91 81 7/24/2024
3.24.718.105 96 7/18/2024
3.24.716.95 124 7/16/2024
3.24.712.94 114 7/12/2024
3.24.710.14 112 7/9/2024
3.24.709.105 121 7/9/2024
3.24.704.94 123 7/4/2024
3.24.701.90 109 7/1/2024
3.24.628.114 115 6/28/2024
3.24.627.145 115 6/27/2024
3.24.620.160 107 6/20/2024
3.24.613.115 103 6/13/2024
3.24.612.95 103 6/12/2024
3.24.528.90 108 5/28/2024
3.24.522.84 122 5/22/2024
3.24.512.213 109 5/12/2024
3.24.508.112 134 5/8/2024
2.2024.428.71 128 4/28/2024
2.2024.427.1128 119 4/27/2024
2.2.72 125 4/14/2024
2.2.71 104 4/12/2024
2.2.8 108 4/26/2024
2.2.6 125 4/10/2024
2.2.5 131 3/26/2024
2.2.4 117 3/25/2024
2.2.3 129 3/24/2024
2.2.2 124 3/21/2024
2.2.1 125 3/20/2024
2.2.0 146 3/13/2024
2.1.9 152 2/21/2024
2.1.8 126 2/18/2024
2.1.7 145 2/16/2024
2.1.6 162 2/14/2024
2.1.5 126 2/14/2024
2.1.4 155 2/9/2024
2.1.3 126 2/8/2024
2.1.2 180 2/5/2024
2.1.1.2 228 12/26/2023
2.1.1.1 125 12/26/2023
2.1.1 138 12/25/2023
2.1.0 152 12/17/2023
2.0.11 206 12/6/2023
2.0.1 207 11/15/2023
2.0.0 159 11/14/2023
1.9.1 171 11/1/2023
1.9.0 143 10/19/2023
1.9.0-preview2 329 10/12/2023
1.9.0-preview1 111 10/12/2023
1.8.9 189 10/11/2023
1.8.8 182 10/11/2023
1.8.7-rc2 143 9/21/2023
1.8.7-rc1 132 9/12/2023
1.8.6 182 8/31/2023
1.8.5 872 8/25/2023
1.8.4 172 8/24/2023
1.8.3 194 8/23/2023
1.8.2 266 8/22/2023
1.8.1 205 8/18/2023
1.8.0 197 8/15/2023
1.7.9 230 8/11/2023
1.7.8 174 8/11/2023
1.7.7 186 8/10/2023
1.7.6 201 8/9/2023
1.7.5 252 8/9/2023
1.7.4 286 8/3/2023
1.7.3 193 8/1/2023
1.7.2 188 7/31/2023
1.7.1 185 7/27/2023
1.7.0 202 7/25/2023
1.6.9 181 7/25/2023
1.6.8 194 7/24/2023
1.6.7 213 7/20/2023
1.6.6 207 7/19/2023
1.6.5 185 7/19/2023
1.6.4 187 7/17/2023
1.6.3 163 7/17/2023
1.6.2 216 7/12/2023
1.6.1 228 6/30/2023
1.6.0 160 6/26/2023
1.5.9 176 6/22/2023
1.5.8 180 6/15/2023
1.5.7.1 181 6/14/2023
1.5.7 178 6/14/2023
1.5.6.2 233 6/7/2023
1.5.6.1 160 6/7/2023
1.5.6 160 6/7/2023
1.5.5.2 220 5/26/2023
1.5.5.1 178 5/26/2023
1.5.5 178 5/26/2023
1.5.4.4 191 5/25/2023
1.5.4.3 232 5/23/2023
1.5.4.2 294 5/17/2023
1.5.4.1 186 5/16/2023
1.5.4 263 5/11/2023
1.5.3 184 5/11/2023
1.5.2 127 5/10/2023
1.5.1 125 5/10/2023
1.5.0 166 5/6/2023
1.4.0 122 5/5/2023
1.3.9 135 4/23/2023
1.3.8.6 117 4/23/2023
1.3.8.5 127 4/21/2023
1.3.8.1 193 4/12/2023
1.3.8 132 4/11/2023
1.3.7 157 4/9/2023
1.3.6.3 214 4/1/2023
1.3.6.2 130 3/31/2023
1.3.6.1 131 3/31/2023
1.3.6 103 3/31/2023
1.3.5 128 3/30/2023
1.3.4.1 189 3/29/2023
1.3.4 136 3/28/2023
1.3.3 112 3/28/2023
1.3.2 145 3/26/2023
1.3.1 200 3/22/2023
1.3.0 139 3/21/2023
1.2.0 124 3/21/2023
1.1.0 139 3/17/2023
1.0.9 135 3/15/2023
1.0.8 137 3/15/2023
1.0.7 116 3/15/2023
1.0.6 134 3/13/2023
1.0.5 140 3/13/2023
1.0.4 116 3/13/2023
1.0.3 205 2/26/2023
1.0.2 127 2/26/2023
1.0.1 135 2/23/2023
1.0.0 296 2/20/2023