EasilyNET.AutoDependencyInjection
1.9.0-preview1
This is a prerelease version of EasilyNET.AutoDependencyInjection.
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.9.0-preview1
NuGet\Install-Package EasilyNET.AutoDependencyInjection -Version 1.9.0-preview1
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-preview1" />
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-preview1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: EasilyNET.AutoDependencyInjection, 1.9.0-preview1"
#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-preview1&prerelease // Install EasilyNET.AutoDependencyInjection as a Cake Tool #tool nuget:?package=EasilyNET.AutoDependencyInjection&version=1.9.0-preview1&prerelease
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 | 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.9.0-preview1)
- EasilyNET.Core (>= 1.9.0-preview1)
-
net7.0
- EasilyNET.AutoDependencyInjection.Core (>= 1.9.0-preview1)
- EasilyNET.Core (>= 1.9.0-preview1)
-
net8.0
- EasilyNET.AutoDependencyInjection.Core (>= 1.9.0-preview1)
- EasilyNET.Core (>= 1.9.0-preview1)
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.1126.231 | 68 | 11/26/2024 |
3.24.1126.172 | 72 | 11/26/2024 |
3.24.1126.114 | 69 | 11/26/2024 |
3.24.1126.104 | 65 | 11/26/2024 |
3.24.1125.181 | 56 | 11/25/2024 |
3.24.1125.104 | 68 | 11/25/2024 |
3.24.1121.183 | 70 | 11/21/2024 |
3.24.1120.183 | 76 | 11/20/2024 |
3.24.1119.31 | 69 | 11/18/2024 |
3.24.1115.143 | 64 | 11/15/2024 |
3.24.1113.100 | 82 | 11/13/2024 |
3.24.1112.125 | 68 | 11/12/2024 |
3.24.1107.140 | 80 | 11/7/2024 |
3.24.1107.54 | 70 | 11/7/2024 |
3.24.1107.34 | 71 | 11/7/2024 |
3.24.1105.111 | 75 | 11/5/2024 |
3.24.1103.31 | 80 | 11/2/2024 |
3.24.1103 | 75 | 11/2/2024 |
3.24.1031.135 | 78 | 10/31/2024 |
3.24.1031.112 | 72 | 10/31/2024 |
3.24.1031.104 | 77 | 10/31/2024 |
3.24.1029.142 | 80 | 10/29/2024 |
3.24.1025.30 | 80 | 10/24/2024 |
3.24.1022.142 | 64 | 10/22/2024 |
3.24.1018.204 | 137 | 10/18/2024 |
3.24.1018.175 | 131 | 10/18/2024 |
3.24.1018.166 | 130 | 10/18/2024 |
3.24.1018.93 | 141 | 10/18/2024 |
3.24.1017.42 | 103 | 10/16/2024 |
3.24.1016.161 | 101 | 10/16/2024 |
3.24.1015.231 | 90 | 10/15/2024 |
3.24.1015.14 | 80 | 10/14/2024 |
3.24.1012.114 | 82 | 10/12/2024 |
3.24.1009.115 | 88 | 10/9/2024 |
3.24.1008.160 | 84 | 10/8/2024 |
3.24.1008.133 | 85 | 10/8/2024 |
3.24.1007.185 | 88 | 10/7/2024 |
3.24.1003.33 | 90 | 10/2/2024 |
3.24.1002.162 | 85 | 10/2/2024 |
3.24.929.143 | 86 | 9/29/2024 |
3.24.929.141 | 74 | 9/29/2024 |
3.24.929.131 | 87 | 9/29/2024 |
3.24.929.122 | 90 | 9/29/2024 |
3.24.926.184 | 87 | 9/26/2024 |
3.24.926.182 | 79 | 9/26/2024 |
3.24.926.175 | 85 | 9/26/2024 |
3.24.924.160 | 90 | 9/24/2024 |
3.24.924.133 | 99 | 9/24/2024 |
3.24.924.124 | 84 | 9/24/2024 |
3.24.924.10 | 89 | 9/23/2024 |
3.24.924.1 | 78 | 9/23/2024 |
3.24.923.234 | 81 | 9/23/2024 |
3.24.923.232 | 87 | 9/23/2024 |
3.24.923.155 | 86 | 9/23/2024 |
3.24.919.92 | 100 | 9/19/2024 |
3.24.914.125 | 113 | 9/14/2024 |
3.24.914.115 | 93 | 9/14/2024 |
3.24.914.111 | 98 | 9/14/2024 |
3.24.911.95 | 102 | 9/11/2024 |
3.24.908.215 | 89 | 9/8/2024 |
3.24.904.200 | 99 | 9/4/2024 |
3.24.828.163 | 121 | 8/28/2024 |
3.24.820.173 | 104 | 8/20/2024 |
3.24.814.92 | 126 | 8/14/2024 |
3.24.812.115 | 105 | 8/12/2024 |
3.24.802.100 | 63 | 8/2/2024 |
3.24.801.162 | 77 | 8/1/2024 |
3.24.801.160 | 68 | 8/1/2024 |
3.24.801.155 | 72 | 8/1/2024 |
3.24.801.153 | 114 | 8/1/2024 |
3.24.730.164 | 73 | 7/30/2024 |
3.24.730.91 | 69 | 7/30/2024 |
3.24.724.91 | 72 | 7/24/2024 |
3.24.718.105 | 86 | 7/18/2024 |
3.24.716.95 | 117 | 7/16/2024 |
3.24.712.94 | 103 | 7/12/2024 |
3.24.710.14 | 99 | 7/9/2024 |
3.24.709.105 | 112 | 7/9/2024 |
3.24.704.94 | 114 | 7/4/2024 |
3.24.701.90 | 100 | 7/1/2024 |
3.24.628.114 | 106 | 6/28/2024 |
3.24.627.145 | 106 | 6/27/2024 |
3.24.620.160 | 98 | 6/20/2024 |
3.24.613.115 | 94 | 6/13/2024 |
3.24.612.95 | 97 | 6/12/2024 |
3.24.528.90 | 101 | 5/28/2024 |
3.24.522.84 | 114 | 5/22/2024 |
3.24.512.213 | 102 | 5/12/2024 |
3.24.508.112 | 127 | 5/8/2024 |
2.2024.428.71 | 123 | 4/28/2024 |
2.2024.427.1128 | 112 | 4/27/2024 |
2.2.72 | 120 | 4/14/2024 |
2.2.71 | 97 | 4/12/2024 |
2.2.8 | 103 | 4/26/2024 |
2.2.6 | 118 | 4/10/2024 |
2.2.5 | 126 | 3/26/2024 |
2.2.4 | 112 | 3/25/2024 |
2.2.3 | 122 | 3/24/2024 |
2.2.2 | 119 | 3/21/2024 |
2.2.1 | 120 | 3/20/2024 |
2.2.0 | 141 | 3/13/2024 |
2.1.9 | 147 | 2/21/2024 |
2.1.8 | 121 | 2/18/2024 |
2.1.7 | 136 | 2/16/2024 |
2.1.6 | 153 | 2/14/2024 |
2.1.5 | 117 | 2/14/2024 |
2.1.4 | 146 | 2/9/2024 |
2.1.3 | 117 | 2/8/2024 |
2.1.2 | 175 | 2/5/2024 |
2.1.1.2 | 223 | 12/26/2023 |
2.1.1.1 | 120 | 12/26/2023 |
2.1.1 | 131 | 12/25/2023 |
2.1.0 | 147 | 12/17/2023 |
2.0.11 | 201 | 12/6/2023 |
2.0.1 | 202 | 11/15/2023 |
2.0.0 | 154 | 11/14/2023 |
1.9.1 | 166 | 11/1/2023 |
1.9.0 | 138 | 10/19/2023 |
1.9.0-preview2 | 321 | 10/12/2023 |
1.9.0-preview1 | 106 | 10/12/2023 |
1.8.9 | 184 | 10/11/2023 |
1.8.8 | 177 | 10/11/2023 |
1.8.7-rc2 | 138 | 9/21/2023 |
1.8.7-rc1 | 127 | 9/12/2023 |
1.8.6 | 177 | 8/31/2023 |
1.8.5 | 835 | 8/25/2023 |
1.8.4 | 167 | 8/24/2023 |
1.8.3 | 189 | 8/23/2023 |
1.8.2 | 261 | 8/22/2023 |
1.8.1 | 200 | 8/18/2023 |
1.8.0 | 192 | 8/15/2023 |
1.7.9 | 225 | 8/11/2023 |
1.7.8 | 169 | 8/11/2023 |
1.7.7 | 181 | 8/10/2023 |
1.7.6 | 196 | 8/9/2023 |
1.7.5 | 247 | 8/9/2023 |
1.7.4 | 279 | 8/3/2023 |
1.7.3 | 186 | 8/1/2023 |
1.7.2 | 181 | 7/31/2023 |
1.7.1 | 178 | 7/27/2023 |
1.7.0 | 195 | 7/25/2023 |
1.6.9 | 174 | 7/25/2023 |
1.6.8 | 187 | 7/24/2023 |
1.6.7 | 208 | 7/20/2023 |
1.6.6 | 202 | 7/19/2023 |
1.6.5 | 178 | 7/19/2023 |
1.6.4 | 182 | 7/17/2023 |
1.6.3 | 158 | 7/17/2023 |
1.6.2 | 211 | 7/12/2023 |
1.6.1 | 223 | 6/30/2023 |
1.6.0 | 155 | 6/26/2023 |
1.5.9 | 171 | 6/22/2023 |
1.5.8 | 175 | 6/15/2023 |
1.5.7.1 | 176 | 6/14/2023 |
1.5.7 | 173 | 6/14/2023 |
1.5.6.2 | 228 | 6/7/2023 |
1.5.6.1 | 155 | 6/7/2023 |
1.5.6 | 155 | 6/7/2023 |
1.5.5.2 | 215 | 5/26/2023 |
1.5.5.1 | 173 | 5/26/2023 |
1.5.5 | 173 | 5/26/2023 |
1.5.4.4 | 186 | 5/25/2023 |
1.5.4.3 | 227 | 5/23/2023 |
1.5.4.2 | 289 | 5/17/2023 |
1.5.4.1 | 181 | 5/16/2023 |
1.5.4 | 258 | 5/11/2023 |
1.5.3 | 179 | 5/11/2023 |
1.5.2 | 122 | 5/10/2023 |
1.5.1 | 120 | 5/10/2023 |
1.5.0 | 161 | 5/6/2023 |
1.4.0 | 117 | 5/5/2023 |
1.3.9 | 130 | 4/23/2023 |
1.3.8.6 | 112 | 4/23/2023 |
1.3.8.5 | 122 | 4/21/2023 |
1.3.8.1 | 188 | 4/12/2023 |
1.3.8 | 127 | 4/11/2023 |
1.3.7 | 152 | 4/9/2023 |
1.3.6.3 | 209 | 4/1/2023 |
1.3.6.2 | 125 | 3/31/2023 |
1.3.6.1 | 126 | 3/31/2023 |
1.3.6 | 98 | 3/31/2023 |
1.3.5 | 123 | 3/30/2023 |
1.3.4.1 | 184 | 3/29/2023 |
1.3.4 | 131 | 3/28/2023 |
1.3.3 | 107 | 3/28/2023 |
1.3.2 | 140 | 3/26/2023 |
1.3.1 | 195 | 3/22/2023 |
1.3.0 | 134 | 3/21/2023 |
1.2.0 | 119 | 3/21/2023 |
1.1.0 | 134 | 3/17/2023 |
1.0.9 | 130 | 3/15/2023 |
1.0.8 | 132 | 3/15/2023 |
1.0.7 | 111 | 3/15/2023 |
1.0.6 | 129 | 3/13/2023 |
1.0.5 | 135 | 3/13/2023 |
1.0.4 | 111 | 3/13/2023 |
1.0.3 | 200 | 2/26/2023 |
1.0.2 | 122 | 2/26/2023 |
1.0.1 | 130 | 2/23/2023 |
1.0.0 | 291 | 2/20/2023 |