kirov-opensource / NAutowired

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

在.net core 3.1 中使用 NAutowired.Core 自动注入控制器中得的值为null #11

Closed youfak closed 3 years ago

youfak commented 3 years ago

namespace Com.macao.electron.Respository.ModelRepository { ///

/// 用户数据接口类 /// [Repository] public partial class UserRepository {

}

}

namespace Com.macao.electron.Service { ///

/// User 业务接口类 /// public interface IUserService { string getTest(); } }

namespace Com.macao.electron.ServiceImpl { ///

/// User 业务接口类 /// [Service] public partial class UserServiceImpl:IUserService { [Autowired] private UserRepository UserDao { get; set; }

    public string getTest() {
        return "你好";
    }

} }

在Startup.cs 配置如下: //将控制器注册为服务 services.AddControllers().AddControllersAsServices(); services.Replace(ServiceDescriptor.Transient<IControllerActivator, NAutowiredControllerActivator>()); //使用自动依赖注入并指定已添加特性的程序集 services.AutoRegisterDependency(new List { "Com.macao.electron.Respository", "Com.macao.electron.Service", "Com.macao.electron.ServiceImpl", "Com.macao.electron" });

namespace Com.macao.electron.Controllers { [Route("[controller]")] [ApiController] public class AuthController : ControllerBase {

    //日志
    [Autowired]
    private ILogger<AuthController> _logger { get; set; }

    [Autowired(typeof(UserServiceImpl))]
    private IUserService UserServiceImpl { get; set; }

} }

FatTigerWang commented 3 years ago

是找到问题了所以关闭了是吗?

youfak commented 3 years ago

是的,已经找到问题了

发送自 Windows 10 版邮件https://go.microsoft.com/fwlink/?LinkId=550986应用

发件人: FatTigermailto:notifications@github.com 发送时间: 2020年11月12日 13:50 收件人: kirov-opensource/NAutowiredmailto:NAutowired@noreply.github.com 抄送: childmailto:wulincheng02@outlook.com; State changemailto:state_change@noreply.github.com 主题: Re: [kirov-opensource/NAutowired] 在.net core 3.1 中使用 NAutowired.Core 自动注入控制器中得的值为null (#11)

是找到问题了所以关闭了是吗?

― You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://github.com/kirov-opensource/NAutowired/issues/11#issuecomment-725854171, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGPBVOHXEARV3HEYH2DFEPDSPNZRBANCNFSM4TS2VBEA.