According to this tutorial, to use Ninject in my Asp.net MVC 3 application , all I have to do is install package via Nuget and configure 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>(); //always null
}
myObject
always returns null.
I've tried kernel.Bind<IReCaptchaValidator>().To<ReCaptchaValidate>().InRequestScope()
, but not effect!
myObject
continues null
In this post here on StackOverflow, I was told to use DependencyResolver.Current.GetService(TYPE)
to retrieve the instance of an object.