Reputation: 755
With the latest version of Unity (MVC5) the InjectionFactory has become deprecated. Below is the Obsolete warning you will receive when trying to use it.
[Obsolete("InjectionFactory has been deprecated and will be removed in next release. Please use IUnityContainer.RegisterFactory(...) method instead.", false)]
Unfortunately I lack the knowledge with this API to put in the appropriate fix.
As you can see from the code below I'm trying to register an IAuthenticationManager using the old solution which leverages InjectionFactory. Does anyone know how this would look with the new solution?
public static void RegisterComponents()
{
var container = new UnityContainer();
container.RegisterType<IAuthenticationManager>(new InjectionFactory(c => HttpContext.Current.GetOwinContext().Authentication));
DependencyResolver.SetResolver(new UnityDependencyResolver(container));
}
Below I've also included a controller which references this object.
public class AccountController : Controller
{
private AdAuthenticationService _signInService;
public AccountController() { }
public AccountController(IAuthenticationManager signInManager)
{
this._signInService = new AdAuthenticationService(signInManager);
}
etc...
Let me know if you all have any other questions and thanks for the help.
Upvotes: 4
Views: 2860
Reputation: 755
I feel a little stupid. I took the time to actually read the warning and the answer was right there.
One line replacement:
Old:
container.RegisterType<IAuthenticationManager>(new InjectionFactory(c => HttpContext.Current.GetOwinContext().Authentication));
New:
container.RegisterFactory<IAuthenticationManager>(c => HttpContext.Current.GetOwinContext().Authentication);
Upvotes: 15