# net 能力库 **Repository Path**: feiyu03/dependency-injection-plug-in ## Basic Information - **Project Name**: net 能力库 - **Description**: 依赖注入插件KyDependencyPlugin 依赖于netsrandard2.1框架的系统容器,实现自动扫描注册 通过扩展库KyCommonExtend .Tostring ,tolong 等通用扩展函数的写,当对象为空时,自动转成需要转的对象的默认值 - **Primary Language**: C# - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2022-05-10 - **Last Updated**: 2026-04-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README KyDependencyPlugin:自动依赖注入插件 > dotnet add package KyDependencyPlugin ``` KyCommonExtend:通用工具扩展库 > dotnet add package KyCommonExtend ## 注册 //扫描文件夹自动注入,默认为根目录,只要继承这三个接口中(ITransient,IScoped, ISingleton)任意一个的非内部类或接口,都可以通过扫描被依赖注入到系统容器中 ``` 接口注册的生命周期: ITransient:瞬时 IScoped:http请求的作用域周期 ISingleton:单例 ``` ``` //第二个参数标识是否是web项目,第三个项目表示自动注册的dll文件夹,默认为根目录 builder.Services.AtuoRegister(builder.Host,isWeb:true,""); ``` #接口实例使用 ``` public class FileBll : IScoped { } ``` ## 获取实例 1、获取单个实例: ``` IFormFile Ifrile= RegisterHelper.GetService ``` 2、根据类名获取实例: ``` IFormFile Ifrile= RegisterHelper.GetService("FileBll"); ``` 3、获取多个实例: ``` IEnumerable< IFormFile> Ifrile= RegisterHelper.GetServices(); ``` 4、通过构造函数使用: ``` public class Test { public FileBll file; public Test(FileBll _file) { file = _file; } } ``` [WITH] (LICENSE)1. 这里是列表文本