29.05.2015 Views

o_19mgorv9t13a3ko71fev19l81mqa.pdf

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}<br />

}<br />

}<br />

Adding the View<br />

decimal totalValue = cart.CalculateProductTotal();<br />

return View(totalValue);<br />

The last addition to the project is the view, called Index. It does not matter which options you check as you create the view as<br />

long as you set the contents to match those shown in Listing 6-5.<br />

Listing 6-5. The Contents of the Index.cshtml File<br />

@model decimal<br />

@{<br />

}<br />

Layout = null;<br />

<br />

<br />

<br />

<br />

Value<br />

<br />

<br />

<br />

Total value is $@Model<br />

<br />

<br />

<br />

This view uses the @Model expression to display the value of the decimal passed from the action method. If you start<br />

the project, you will see the total value, as calculated by the LinqValueCalculator class, illustrated by Figure 6-1. This<br />

is a simple project, but it sets the scene for the different tools and techniques that I describe in this chapter.<br />

Figure 6-1. Testing the example app<br />

Using Ninject<br />

I introduced dependency injection (DI) in Chapter 3. To recap, the idea is to decouple the components in an MVC application, with<br />

a combination of interfaces and DI container that creates instances of objects by creating implementations of the interfaces they<br />

depend on and injecting them into the constructor.<br />

131

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!