EasilyNET.AutoDependencyInjection
1.8.4
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 1.8.4
NuGet\Install-Package EasilyNET.AutoDependencyInjection -Version 1.8.4
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.8.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EasilyNET.AutoDependencyInjection --version 1.8.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: EasilyNET.AutoDependencyInjection, 1.8.4"
#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.8.4
// Install EasilyNET.AutoDependencyInjection as a Cake Tool
#tool nuget:?package=EasilyNET.AutoDependencyInjection&version=1.8.4
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();
- c.使用属性注入服务
- 在 Program.cs 中添加如下代码:
//使用属性注入
builder.Host.UsePropertyInjection();
...
var app = builder.Build();
- 使用特性通过属性注入服务
// 通过字段注入
[Injection]
private readonly ITest? _test = null;
// 通过属性注入
[Injection]
public ITest1? Test1 { get; set; };
Product | Versions 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- EasilyNET.AutoDependencyInjection.Core (>= 1.8.4)
- EasilyNET.Core (>= 1.8.4)
-
net7.0
- EasilyNET.AutoDependencyInjection.Core (>= 1.8.4)
- EasilyNET.Core (>= 1.8.4)
-
net8.0
- EasilyNET.AutoDependencyInjection.Core (>= 1.8.4)
- EasilyNET.Core (>= 1.8.4)
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.628.114 | 33 | 6/28/2024 |
3.24.627.145 | 31 | 6/27/2024 |
3.24.620.160 | 64 | 6/20/2024 |
3.24.613.115 | 66 | 6/13/2024 |
3.24.612.95 | 69 | 6/12/2024 |
3.24.528.90 | 74 | 5/28/2024 |
3.24.522.84 | 87 | 5/22/2024 |
3.24.512.213 | 78 | 5/12/2024 |
3.24.508.112 | 89 | 5/8/2024 |
2.2024.428.71 | 86 | 4/28/2024 |
2.2024.427.1128 | 87 | 4/27/2024 |
2.2.72 | 94 | 4/14/2024 |
2.2.71 | 73 | 4/12/2024 |
2.2.8 | 77 | 4/26/2024 |
2.2.6 | 91 | 4/10/2024 |
2.2.5 | 93 | 3/26/2024 |
2.2.4 | 82 | 3/25/2024 |
2.2.3 | 98 | 3/24/2024 |
2.2.2 | 93 | 3/21/2024 |
2.2.1 | 87 | 3/20/2024 |
2.2.0 | 106 | 3/13/2024 |
2.1.9 | 121 | 2/21/2024 |
2.1.8 | 90 | 2/18/2024 |
2.1.7 | 100 | 2/16/2024 |
2.1.6 | 104 | 2/14/2024 |
2.1.5 | 93 | 2/14/2024 |
2.1.4 | 115 | 2/9/2024 |
2.1.3 | 94 | 2/8/2024 |
2.1.2 | 113 | 2/5/2024 |
2.1.1.2 | 188 | 12/26/2023 |
2.1.1.1 | 88 | 12/26/2023 |
2.1.1 | 102 | 12/25/2023 |
2.1.0 | 136 | 12/17/2023 |
2.0.11 | 165 | 12/6/2023 |
2.0.1 | 157 | 11/15/2023 |
2.0.0 | 127 | 11/14/2023 |
1.9.1 | 131 | 11/1/2023 |
1.9.0 | 108 | 10/19/2023 |
1.9.0-preview2 | 250 | 10/12/2023 |
1.9.0-preview1 | 94 | 10/12/2023 |
1.8.9 | 156 | 10/11/2023 |
1.8.8 | 150 | 10/11/2023 |
1.8.7-rc2 | 110 | 9/21/2023 |
1.8.7-rc1 | 92 | 9/12/2023 |
1.8.6 | 144 | 8/31/2023 |
1.8.5 | 548 | 8/25/2023 |
1.8.4 | 139 | 8/24/2023 |
1.8.3 | 153 | 8/23/2023 |
1.8.2 | 229 | 8/22/2023 |
1.8.1 | 165 | 8/18/2023 |
1.8.0 | 161 | 8/15/2023 |
1.7.9 | 201 | 8/11/2023 |
1.7.8 | 144 | 8/11/2023 |
1.7.7 | 164 | 8/10/2023 |
1.7.6 | 162 | 8/9/2023 |
1.7.5 | 215 | 8/9/2023 |
1.7.4 | 254 | 8/3/2023 |
1.7.3 | 156 | 8/1/2023 |
1.7.2 | 158 | 7/31/2023 |
1.7.1 | 155 | 7/27/2023 |
1.7.0 | 164 | 7/25/2023 |
1.6.9 | 145 | 7/25/2023 |
1.6.8 | 157 | 7/24/2023 |
1.6.7 | 174 | 7/20/2023 |
1.6.6 | 177 | 7/19/2023 |
1.6.5 | 149 | 7/19/2023 |
1.6.4 | 156 | 7/17/2023 |
1.6.3 | 135 | 7/17/2023 |
1.6.2 | 189 | 7/12/2023 |
1.6.1 | 193 | 6/30/2023 |
1.6.0 | 130 | 6/26/2023 |
1.5.9 | 139 | 6/22/2023 |
1.5.8 | 146 | 6/15/2023 |
1.5.7.1 | 152 | 6/14/2023 |
1.5.7 | 161 | 6/14/2023 |
1.5.6.2 | 196 | 6/7/2023 |
1.5.6.1 | 123 | 6/7/2023 |
1.5.6 | 132 | 6/7/2023 |
1.5.5.2 | 181 | 5/26/2023 |
1.5.5.1 | 151 | 5/26/2023 |
1.5.5 | 151 | 5/26/2023 |
1.5.4.4 | 157 | 5/25/2023 |
1.5.4.3 | 190 | 5/23/2023 |
1.5.4.2 | 257 | 5/17/2023 |
1.5.4.1 | 147 | 5/16/2023 |
1.5.4 | 227 | 5/11/2023 |
1.5.3 | 148 | 5/11/2023 |
1.5.2 | 103 | 5/10/2023 |
1.5.1 | 102 | 5/10/2023 |
1.5.0 | 148 | 5/6/2023 |
1.4.0 | 98 | 5/5/2023 |
1.3.9 | 110 | 4/23/2023 |
1.3.8.6 | 98 | 4/23/2023 |
1.3.8.5 | 108 | 4/21/2023 |
1.3.8.1 | 168 | 4/12/2023 |
1.3.8 | 107 | 4/11/2023 |
1.3.7 | 132 | 4/9/2023 |
1.3.6.3 | 188 | 4/1/2023 |
1.3.6.2 | 111 | 3/31/2023 |
1.3.6.1 | 105 | 3/31/2023 |
1.3.6 | 84 | 3/31/2023 |
1.3.5 | 105 | 3/30/2023 |
1.3.4.1 | 167 | 3/29/2023 |
1.3.4 | 118 | 3/28/2023 |
1.3.3 | 88 | 3/28/2023 |
1.3.2 | 121 | 3/26/2023 |
1.3.1 | 178 | 3/22/2023 |
1.3.0 | 122 | 3/21/2023 |
1.2.0 | 100 | 3/21/2023 |
1.1.0 | 117 | 3/17/2023 |
1.0.9 | 114 | 3/15/2023 |
1.0.8 | 114 | 3/15/2023 |
1.0.7 | 93 | 3/15/2023 |
1.0.6 | 117 | 3/13/2023 |
1.0.5 | 117 | 3/13/2023 |
1.0.4 | 95 | 3/13/2023 |
1.0.3 | 186 | 2/26/2023 |
1.0.2 | 104 | 2/26/2023 |
1.0.1 | 112 | 2/23/2023 |
1.0.0 | 258 | 2/20/2023 |