I'm trying to replicate the following Ninject syntax in Unity, but not having any luck:
Bind<IIdentity>().ToMethod(c => HttpContext.Current.User.Identity);
I'm thinking it ought to look something like:
IUnityContainer container;
...
container.RegisterType<IIdentity>(HttpContext.Current.User.Identity);
How should it be?
While neontapir's answer could work, that extension method is Obsolete. The correct way to do this now would be to use an InjectionFactory:
container.RegisterType<IIdentity>(new InjectionFactory(u => HttpContext.Current.User.Identity));
container.RegisterInstance<IIdentity>(...);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With