Before getting started lets make sure everyone is on the same page. The screenshots and descriptions below assume the use of the following products and tools.
- Visual Studio 2010
- ASP.NET MVC 3
- .NET 4.0 framework
Lets start by creating a new ASP.NET MVC 3 Web Application
Lets go ahead and choose the Empty template. We can bypass using a Test Project at this time.
Once the solution is created lets add the following folder structure:
Inside the service folder lets add an interface for a messaging service called IMessagingService. We will be using the messaging service in our home controller that we will be creating in the next couple of steps. Here is the code that should be in the messaging service interface.
Now lets create the actual messaging service class also in the service folder. Here is the code that should be in the messaging service class.
Your folder and file structure should look something like this.
Now lets go ahead and add a HomeController to the Controllers folder. Here is the code for the first Home Controller.
Now before we can actually run our application we need to install Ninject. Lets do this by right clicking the project in the Solution Explorer and selecting “Add Library Package Reference”. You should see a window that looks like this.
- Click the “Online” item in the accordion.
- Search fro “ninject”.
- Click the install button next to Ninject.MVC3.
- After a few moments the install button will go away and a green check mark will be displayed. Go ahead and close the window.
You should now see two new references added to your project. One for Ninject and the other for Ninject.MVC3. You should also see a file called “AppStart_NinjectMVC3.cs” added to the root of your folder. Modify the “AppStart_NinjectMVC3.cs” file to look like this.
Note that in the RegisterServices method I added a new kernel.Bind line that tells the application that anytime I see a IMessagingService reference, new up and send in a MessagingService.
There are no other modifications needed. If you run the application the Home\Index route should return the text “Hello World” in the browser window.