可能重复:
通过构造函数或属性设置器进行依赖注入?
如果Property Injection比Constructor Injection有任何优势,我很好奇:
public class LoginController : Controller
{
[Inject]
public ICookiesManager CookiesManager {get; set;}
[Inject]
public ISecurityManager SecurityManager {get; set;}
public LoginController()
{
}
}
对比
public class LoginController : Controller
{
private ICookiesManager _cookiesManager;
private ISecurityManager _securityManager;
public LoginController(ICookiesManager cookiesManager, ISecurityManager securityManager)
{
_securityManager = securityManager;
_cookiesManager = cookiesManager;
}
}