EasilyNET.AutoDependencyInjection
3.24.508.112
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package EasilyNET.AutoDependencyInjection --version 3.24.508.112
NuGet\Install-Package EasilyNET.AutoDependencyInjection -Version 3.24.508.112
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="3.24.508.112" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EasilyNET.AutoDependencyInjection --version 3.24.508.112
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: EasilyNET.AutoDependencyInjection, 3.24.508.112"
#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=3.24.508.112
// Install EasilyNET.AutoDependencyInjection as a Cake Tool
#tool nuget:?package=EasilyNET.AutoDependencyInjection&version=3.24.508.112
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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 | Versions 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- EasilyNET.AutoDependencyInjection.Core (>= 3.24.508.112)
- EasilyNET.Core (>= 3.24.508.112)
-
net9.0
- EasilyNET.AutoDependencyInjection.Core (>= 3.24.508.112)
- EasilyNET.Core (>= 3.24.508.112)
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.24.528.90 | 71 | 5/28/2024 |
3.24.522.84 | 84 | 5/22/2024 |
3.24.512.213 | 77 | 5/12/2024 |
3.24.508.112 | 87 | 5/8/2024 |
2.2024.428.71 | 85 | 4/28/2024 |
2.2024.427.1128 | 86 | 4/27/2024 |
2.2.72 | 92 | 4/14/2024 |
2.2.71 | 72 | 4/12/2024 |
2.2.8 | 76 | 4/26/2024 |
2.2.6 | 90 | 4/10/2024 |
2.2.5 | 92 | 3/26/2024 |
2.2.4 | 81 | 3/25/2024 |
2.2.3 | 91 | 3/24/2024 |
2.2.2 | 92 | 3/21/2024 |
2.2.1 | 86 | 3/20/2024 |
2.2.0 | 105 | 3/13/2024 |
2.1.9 | 120 | 2/21/2024 |
2.1.8 | 89 | 2/18/2024 |
2.1.7 | 99 | 2/16/2024 |
2.1.6 | 103 | 2/14/2024 |
2.1.5 | 87 | 2/14/2024 |
2.1.4 | 114 | 2/9/2024 |
2.1.3 | 93 | 2/8/2024 |
2.1.2 | 106 | 2/5/2024 |
2.1.1.2 | 186 | 12/26/2023 |
2.1.1.1 | 87 | 12/26/2023 |
2.1.1 | 96 | 12/25/2023 |
2.1.0 | 135 | 12/17/2023 |
2.0.11 | 164 | 12/6/2023 |
2.0.1 | 156 | 11/15/2023 |
2.0.0 | 126 | 11/14/2023 |
1.9.1 | 130 | 11/1/2023 |
1.9.0 | 107 | 10/19/2023 |
1.9.0-preview2 | 247 | 10/12/2023 |
1.9.0-preview1 | 93 | 10/12/2023 |
1.8.9 | 155 | 10/11/2023 |
1.8.8 | 143 | 10/11/2023 |
1.8.7-rc2 | 109 | 9/21/2023 |
1.8.7-rc1 | 91 | 9/12/2023 |
1.8.6 | 143 | 8/31/2023 |
1.8.5 | 347 | 8/25/2023 |
1.8.4 | 138 | 8/24/2023 |
1.8.3 | 152 | 8/23/2023 |
1.8.2 | 228 | 8/22/2023 |
1.8.1 | 164 | 8/18/2023 |
1.8.0 | 160 | 8/15/2023 |
1.7.9 | 200 | 8/11/2023 |
1.7.8 | 143 | 8/11/2023 |
1.7.7 | 163 | 8/10/2023 |
1.7.6 | 161 | 8/9/2023 |
1.7.5 | 214 | 8/9/2023 |
1.7.4 | 252 | 8/3/2023 |
1.7.3 | 155 | 8/1/2023 |
1.7.2 | 151 | 7/31/2023 |
1.7.1 | 148 | 7/27/2023 |
1.7.0 | 163 | 7/25/2023 |
1.6.9 | 144 | 7/25/2023 |
1.6.8 | 156 | 7/24/2023 |
1.6.7 | 173 | 7/20/2023 |
1.6.6 | 176 | 7/19/2023 |
1.6.5 | 148 | 7/19/2023 |
1.6.4 | 155 | 7/17/2023 |
1.6.3 | 134 | 7/17/2023 |
1.6.2 | 188 | 7/12/2023 |
1.6.1 | 192 | 6/30/2023 |
1.6.0 | 129 | 6/26/2023 |
1.5.9 | 138 | 6/22/2023 |
1.5.8 | 145 | 6/15/2023 |
1.5.7.1 | 151 | 6/14/2023 |
1.5.7 | 160 | 6/14/2023 |
1.5.6.2 | 195 | 6/7/2023 |
1.5.6.1 | 122 | 6/7/2023 |
1.5.6 | 131 | 6/7/2023 |
1.5.5.2 | 180 | 5/26/2023 |
1.5.5.1 | 150 | 5/26/2023 |
1.5.5 | 150 | 5/26/2023 |
1.5.4.4 | 156 | 5/25/2023 |
1.5.4.3 | 189 | 5/23/2023 |
1.5.4.2 | 255 | 5/17/2023 |
1.5.4.1 | 146 | 5/16/2023 |
1.5.4 | 226 | 5/11/2023 |
1.5.3 | 147 | 5/11/2023 |
1.5.2 | 102 | 5/10/2023 |
1.5.1 | 101 | 5/10/2023 |
1.5.0 | 147 | 5/6/2023 |
1.4.0 | 97 | 5/5/2023 |
1.3.9 | 109 | 4/23/2023 |
1.3.8.6 | 97 | 4/23/2023 |
1.3.8.5 | 101 | 4/21/2023 |
1.3.8.1 | 167 | 4/12/2023 |
1.3.8 | 106 | 4/11/2023 |
1.3.7 | 131 | 4/9/2023 |
1.3.6.3 | 187 | 4/1/2023 |
1.3.6.2 | 104 | 3/31/2023 |
1.3.6.1 | 104 | 3/31/2023 |
1.3.6 | 83 | 3/31/2023 |
1.3.5 | 104 | 3/30/2023 |
1.3.4.1 | 166 | 3/29/2023 |
1.3.4 | 111 | 3/28/2023 |
1.3.3 | 87 | 3/28/2023 |
1.3.2 | 120 | 3/26/2023 |
1.3.1 | 177 | 3/22/2023 |
1.3.0 | 121 | 3/21/2023 |
1.2.0 | 99 | 3/21/2023 |
1.1.0 | 116 | 3/17/2023 |
1.0.9 | 113 | 3/15/2023 |
1.0.8 | 113 | 3/15/2023 |
1.0.7 | 92 | 3/15/2023 |
1.0.6 | 112 | 3/13/2023 |
1.0.5 | 116 | 3/13/2023 |
1.0.4 | 94 | 3/13/2023 |
1.0.3 | 185 | 2/26/2023 |
1.0.2 | 103 | 2/26/2023 |
1.0.1 | 111 | 2/23/2023 |
1.0.0 | 256 | 2/20/2023 |