kirov-opensource / NAutowired

ASP.NET CORE Field Injection Implement
MIT License
77 stars 16 forks source link

AddAutoDependencyInjection找不到 #15

Closed qinqoushui closed 3 years ago

qinqoushui commented 3 years ago

你好,AddAutoDependencyInjection无法使用

FatTigerWang commented 3 years ago

请问你是如何使用的呢?最好能展示一部分代码方便我排查问题

qinqoushui commented 3 years ago

你好,我下载源码后搜索该方法未能找到。我自己的代码是一个aspnetcore3.1 的项目,startup代码节选如下:

 public virtual void ConfigureServices(IServiceCollection services)
 {

   //AutoWired
//控制器属性注入正常
            services.AddControllers().AddControllersAsServices();
            services.Replace(ServiceDescriptor.Transient<IControllerActivator, NAutowiredControllerActivator>());
//试图使用 [Service] [Repository] [Component],在业务类中声明正常,但在startup中无法编译,划红线
            services.AddAutoDependencyInjection(new List<string> { "Test" });
}

nuget引用如下:

<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
    <PackageReference Include="BuildBundlerMinifier" Version="3.2.447" />
    <PackageReference Include="DevExtreme.AspNet.Core" Version="19.2.3" />
    <PackageReference Include="DevExtreme.AspNet.Data" Version="2.5.1" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.10" />
    <PackageReference Include="Microsoft.AspNetCore.Hosting.WindowsServices" Version="3.1.4" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.4" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.4" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.4" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
    <PackageReference Include="NAutowired" Version="2.2.0" />
    <PackageReference Include="QCommon.Standard" Version="1.0.56" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
    <PackageReference Include="System.Text.Encoding.CodePages" Version="4.7.1" />

请问如何解决

FatTigerWang commented 3 years ago

请使用

services.AutoRegisterDependency(new List<string> { "Test" });

AddAutoDependencyInjection是在哪看到的呢?这应当是以前版本的一个方法,是否是升级包之后导致的问题?

文档请查看进阶

qinqoushui commented 3 years ago

在首页上看到的,https://github.com/kirov-opensource/NAutowired 这个方法能找到,非常感谢!

FatTigerWang commented 3 years ago

好的,文档已经更新,是个文档错误