Asp.net mvc 使用Unity MVC5的依赖项注入-不推荐使用注入工厂
在最新版本的Unity MVC5中,InjectionFactory已被弃用。下面是您尝试使用时将收到的过时警告Asp.net mvc 使用Unity MVC5的依赖项注入-不推荐使用注入工厂,asp.net-mvc,dependency-injection,owin,Asp.net Mvc,Dependency Injection,Owin,在最新版本的Unity MVC5中,InjectionFactory已被弃用。下面是您尝试使用时将收到的过时警告 [Obsolete("InjectionFactory has been deprecated and will be removed in next release. Please use IUnityContainer.RegisterFactory(...) method instead.", false)] 不幸的是,我缺乏这个API的知识来进行适当的修复 从下面的代码中可
[Obsolete("InjectionFactory has been deprecated and will be removed in next release. Please use IUnityContainer.RegisterFactory(...) method instead.", false)]
不幸的是,我缺乏这个API的知识来进行适当的修复
从下面的代码中可以看到,我正在尝试使用利用InjectionFactory的旧解决方案注册IAAuthenticationManager。有人知道新解决方案会是什么样子吗
public static void RegisterComponents()
{
var container = new UnityContainer();
container.RegisterType<IAuthenticationManager>(new InjectionFactory(c => HttpContext.Current.GetOwinContext().Authentication));
DependencyResolver.SetResolver(new UnityDependencyResolver(container));
}
如果你们还有其他问题,请告诉我,谢谢你们的帮助。我觉得有点傻。我花时间仔细阅读了警告,答案就在那里 单线更换: 旧的: 新的:
我觉得有点傻。我花时间仔细阅读了警告,答案就在那里 单线更换: 旧的: 新的:
public class AccountController : Controller
{
private AdAuthenticationService _signInService;
public AccountController() { }
public AccountController(IAuthenticationManager signInManager)
{
this._signInService = new AdAuthenticationService(signInManager);
}
etc...
container.RegisterType<IAuthenticationManager>(new InjectionFactory(c => HttpContext.Current.GetOwinContext().Authentication));
container.RegisterFactory<IAuthenticationManager>(c => HttpContext.Current.GetOwinContext().Authentication);