EasilyNET.AutoDependencyInjection 1.0.7

There is a newer version of this package available.
See the version list below for details.
dotnet add package EasilyNET.AutoDependencyInjection --version 1.0.7
                    
NuGet\Install-Package EasilyNET.AutoDependencyInjection -Version 1.0.7
                    
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.0.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EasilyNET.AutoDependencyInjection" Version="1.0.7" />
                    
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 1.0.7
                    
#r "nuget: EasilyNET.AutoDependencyInjection, 1.0.7"
                    
#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=1.0.7
                    
Install EasilyNET.AutoDependencyInjection as a Cake Addin
#tool nuget:?package=EasilyNET.AutoDependencyInjection&version=1.0.7
                    
Install EasilyNET.AutoDependencyInjection 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 net5.0 was computed.  net5.0-windows was computed.  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.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.526.140 60 4 days ago
4.25.513.101 228 17 days ago
4.25.506.150 144 24 days ago
4.25.429.162 131 a month ago
4.25.429.103 156 a month ago
4.25.411.142 143 2 months ago
4.25.409.92 159 2 months ago
4.25.403.133 162 2 months ago
4.25.319.113 157 2 months ago
4.25.312.103 168 3 months ago
4.25.227.135 113 3 months ago
4.25.221.115 103 3 months ago
4.25.212.95 123 4 months ago
4.25.211.140 107 4 months ago
4.25.124.223 104 4 months ago
4.25.116.110 97 4 months ago
4.25.115.121 64 4 months ago
4.25.114.172 78 5 months ago
4.25.109.111 76 5 months ago
4.25.108.182 79 5 months ago
4.25.108.160 76 5 months ago
4.25.1.1 125 5 months ago
3.24.1224.141 100 5 months ago
3.24.1216.116 131 5 months ago
3.24.1206.100 113 6 months ago
3.24.1205.171 118 6 months ago
3.24.1202.150 110 6 months ago
3.24.1126.231 112 6 months ago
3.24.1126.172 108 6 months ago
3.24.1126.114 107 6 months ago
3.24.1126.104 100 6 months ago
3.24.1125.181 97 6 months ago
3.24.1125.104 111 6 months ago
3.24.1121.183 107 6 months ago
3.24.1120.183 110 6 months ago
3.24.1119.31 106 6 months ago
3.24.1115.143 96 6 months ago
3.24.1113.100 119 7 months ago
3.24.1112.125 101 7 months ago
3.24.1107.140 114 7 months ago
3.24.1107.54 102 7 months ago
3.24.1107.34 104 7 months ago
3.24.1105.111 107 7 months ago
3.24.1103.31 113 7 months ago
3.24.1103 108 7 months ago
3.24.1031.135 113 7 months ago
3.24.1031.112 107 7 months ago
3.24.1031.104 111 7 months ago
3.24.1029.142 116 7 months ago
3.24.1025.30 112 7 months ago
3.24.1022.142 95 7 months ago
3.24.1018.204 165 7 months ago
3.24.1018.175 155 7 months ago
3.24.1018.166 154 7 months ago
3.24.1018.93 167 7 months ago
3.24.1017.42 127 7 months ago
3.24.1016.161 127 7 months ago
3.24.1015.231 117 7 months ago
3.24.1015.14 103 7 months ago
3.24.1012.114 105 8 months ago
3.24.1009.115 112 8 months ago
3.24.1008.160 111 8 months ago
3.24.1008.133 111 8 months ago
3.24.1007.185 115 8 months ago
3.24.1003.33 117 8 months ago
3.24.1002.162 113 8 months ago
3.24.929.143 111 8 months ago
3.24.929.141 96 8 months ago
3.24.929.131 114 8 months ago
3.24.929.122 114 8 months ago
3.24.926.184 114 8 months ago
3.24.926.182 103 8 months ago
3.24.926.175 110 8 months ago
3.24.924.160 116 8 months ago
3.24.924.133 121 8 months ago
3.24.924.124 108 8 months ago
3.24.924.10 116 8 months ago
3.24.924.1 105 8 months ago
3.24.923.234 109 8 months ago
3.24.923.232 114 8 months ago
3.24.923.155 118 8 months ago
3.24.919.92 129 8 months ago
3.24.914.125 136 9 months ago
3.24.914.115 117 9 months ago
3.24.914.111 121 9 months ago
3.24.911.95 126 9 months ago
3.24.908.215 113 9 months ago
3.24.904.200 122 9 months ago
3.24.828.163 146 9 months ago
3.24.820.173 128 9 months ago
3.24.814.92 150 10 months ago
3.24.812.115 129 10 months ago
3.24.802.100 85 10 months ago
3.24.801.162 100 10 months ago
3.24.801.160 91 10 months ago
3.24.801.155 93 10 months ago
3.24.801.153 141 10 months ago
3.24.730.164 98 10 months ago
3.24.730.91 94 10 months ago
3.24.724.91 95 7/24/2024
3.24.718.105 109 7/18/2024
3.24.716.95 153 7/16/2024
3.24.712.94 129 7/12/2024
3.24.710.14 127 7/9/2024
3.24.709.105 134 7/9/2024
3.24.704.94 140 7/4/2024
3.24.701.90 124 7/1/2024
3.24.628.114 130 6/28/2024
3.24.627.145 130 6/27/2024
3.24.620.160 123 6/20/2024
3.24.613.115 116 6/13/2024
3.24.612.95 119 6/12/2024
3.24.528.90 123 5/28/2024
3.24.522.84 137 5/22/2024
3.24.512.213 124 5/12/2024
3.24.508.112 148 5/8/2024
2.2024.428.71 142 4/28/2024
2.2024.427.1128 131 4/27/2024
2.2.72 140 4/14/2024
2.2.71 118 4/12/2024
2.2.8 122 4/26/2024
2.2.6 143 4/10/2024
2.2.5 147 3/26/2024
2.2.4 133 3/25/2024
2.2.3 145 3/24/2024
2.2.2 138 3/21/2024
2.2.1 140 3/20/2024
2.2.0 164 3/13/2024
2.1.9 170 2/21/2024
2.1.8 145 2/18/2024
2.1.7 159 2/16/2024
2.1.6 175 2/14/2024
2.1.5 141 2/14/2024
2.1.4 167 2/9/2024
2.1.3 141 2/8/2024
2.1.2 195 2/5/2024
2.1.1.2 239 12/26/2023
2.1.1.1 138 12/26/2023
2.1.1 150 12/25/2023
2.1.0 167 12/17/2023
2.0.11 209 12/6/2023
2.0.1 210 11/15/2023
2.0.0 162 11/14/2023
1.9.1 176 11/1/2023
1.9.0 148 10/19/2023
1.9.0-preview2 355 10/12/2023
1.9.0-preview1 114 10/12/2023
1.8.9 193 10/11/2023
1.8.8 185 10/11/2023
1.8.7-rc2 145 9/21/2023
1.8.7-rc1 135 9/12/2023
1.8.6 189 8/31/2023
1.8.5 889 8/25/2023
1.8.4 180 8/24/2023
1.8.3 202 8/23/2023
1.8.2 272 8/22/2023
1.8.1 214 8/18/2023
1.8.0 205 8/15/2023
1.7.9 239 8/11/2023
1.7.8 181 8/11/2023
1.7.7 195 8/10/2023
1.7.6 208 8/9/2023
1.7.5 259 8/9/2023
1.7.4 295 8/3/2023
1.7.3 202 8/1/2023
1.7.2 196 7/31/2023
1.7.1 194 7/27/2023
1.7.0 211 7/25/2023
1.6.9 191 7/25/2023
1.6.8 201 7/24/2023
1.6.7 223 7/20/2023
1.6.6 221 7/19/2023
1.6.5 195 7/19/2023
1.6.4 198 7/17/2023
1.6.3 172 7/17/2023
1.6.2 228 7/12/2023
1.6.1 237 6/30/2023
1.6.0 169 6/26/2023
1.5.9 184 6/22/2023
1.5.8 194 6/15/2023
1.5.7.1 194 6/14/2023
1.5.7 191 6/14/2023
1.5.6.2 247 6/7/2023
1.5.6.1 176 6/7/2023
1.5.6 175 6/7/2023
1.5.5.2 234 5/26/2023
1.5.5.1 195 5/26/2023
1.5.5 191 5/26/2023
1.5.4.4 204 5/25/2023
1.5.4.3 248 5/23/2023
1.5.4.2 313 5/17/2023
1.5.4.1 203 5/16/2023
1.5.4 280 5/11/2023
1.5.3 200 5/11/2023
1.5.2 144 5/10/2023
1.5.1 141 5/10/2023
1.5.0 185 5/6/2023
1.4.0 139 5/5/2023
1.3.9 150 4/23/2023
1.3.8.6 133 4/23/2023
1.3.8.5 142 4/21/2023
1.3.8.1 208 4/12/2023
1.3.8 148 4/11/2023
1.3.7 174 4/9/2023
1.3.6.3 231 4/1/2023
1.3.6.2 146 3/31/2023
1.3.6.1 147 3/31/2023
1.3.6 120 3/31/2023
1.3.5 144 3/30/2023
1.3.4.1 209 3/29/2023
1.3.4 153 3/28/2023
1.3.3 129 3/28/2023
1.3.2 163 3/26/2023
1.3.1 216 3/22/2023
1.3.0 155 3/21/2023
1.2.0 141 3/21/2023
1.1.0 155 3/17/2023
1.0.9 152 3/15/2023
1.0.8 154 3/15/2023
1.0.7 133 3/15/2023
1.0.6 151 3/13/2023
1.0.5 156 3/13/2023
1.0.4 132 3/13/2023
1.0.3 222 2/26/2023
1.0.2 142 2/26/2023
1.0.1 155 2/23/2023
1.0.0 314 2/20/2023