According to this tutorial , to use Ninject in my MVC 3 application for Asp.net, all I need to do is install the package through Nuget and configure the dependencies.
Follow these steps
Install package-Ninject.MVC3
In NinjectMVC3.cs
private static void RegisterServices(IKernel kernel) { kernel.Bind<IReCaptchaValidator>().To<ReCaptchaValidate>(); }
In controller
[HttpPost] [ValidateAntiForgeryToken] public ActionResult Registe(RegisterModel model) { var myObject = DependencyResolver.Current.GetService<IReCaptchaValidator>();
myObject always returns null.
I tried kernel.Bind<IReCaptchaValidator>().To<ReCaptchaValidate>().InRequestScope() , but not the effect!
myObject continues null
In this post here at StackOverflow, I was told to use DependencyResolver.Current.GetService(TYPE) to retrieve an instance of an object.
c # dependency-injection asp.net-mvc-3 ninject
ridermansb
source share