这个 vs 2019的插件,可以快速把构造函数参数,赋给类的局部私有变量,提高写依赖注入的效率
示例:原始代码
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; } }
下载地址:
https://files.cnblogs.com/files/IWings/DependencyInjectionVSIX.zip
源码:
https://github.com/simpleway2016/DependencyInjectionVSIX.git