酱醋茶有话说:
这种在线的大家都会安装,接下来这种离线的拓展安装包,下载完成后关闭VS直接双击Vsix文件即可,然后重启VS。
这个 vs 的插件,可以快速把构造函数参数,赋给类的局部私有变量,提高写依赖注入的效率
示例:原始代码
public class TestClass { public TestClass(ILogger<TestClass> logger , IServiceProvider serviceProvider) { } }
把光标定在class内部,按下 ALT + 0 快捷键,变成下面这样:
public class TestClass { ILogger<TestClass> _logger; IServiceProvider _serviceProvider; public TestClass(ILogger<TestClass> logger, IServiceProvider serviceProvider) { this._logger = logger; this._serviceProvider = serviceProvider; } }
下载地址:
vs2019:
https://files.cnblogs.com/files/IWings/DependencyInjectionVSIX.zip
vs2022:
https://files.cnblogs.com/files/IWings/DependencyInjectionVsix2022.zip
源码:
https://e.coding.net/IWay2018/dependencyinjectionvsix2022/DependencyInjectionVsix2022.git
转载自:https://www.cnblogs.com/IWings/p/13504281.html