Geeks With Blogs

News Please visit me at my new blog!!

profile for Aligned at Stack Overflow, Q&A for professional and enthusiast programmers
"free in Christ Jesus from the law of sin and death." Romans 8:2 (ESV) Check out the Falling Plates video on YouTube.
more about the Gospel
And then listen to Francis Chan speaking at LifeLight in SD.

Programming and Learning from SD
  1. enable package restore on solution
  2. Nuget Ninject.MVC3 (pre-release available?)
    * adds Ninject, Ninject.Web.Common, Ninject.Web.Mvc
    * App_Start/NinjectWebCommon.cs -> has WebActivator.PreApplicationStartMethod attribute -> runs at startup
  3. add interface and class for testing (IBikeManager and BikeManager)
  4. add controller constructor to HomeController that takes in the interface
    - run website => Error
    "Error activating IBikeManager
    No matching bindings are available, and the type is not self-bindable.
    Activation path:
    2) Injection of dependency IBikeManager into parameter bikeManager of constructor of type HomeController
    1) Request for HomeController"
  5. in NinjectWebCommon, register the services in the RegisterServices Method
  6. kill the IISExpress instance (this only runs on app startup, so you’ll have to do this each time you register a new service), restart app (ctrl + F5)
  7. HomeController now gets loaded with the IBikeManager in the constructor (set breakpoint and start with F5 to prove it)

That’s all there is to using Ninject as you IoC container and constructor injection (Dependency Injection aka DI) working with MVC (3, 4, or 5).

Posted on Wednesday, November 20, 2013 10:46 AM MVC , Unit Testing , Inversion Of Control (Ioc) , Tools , ASP.Net , Dependency Injection | Back to top

Comments on this post: Steps to Get MVC running with Ninject

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Aligned | Powered by: