Setting Up Dependency Injection
We want to be able to use the IRepository
interface without needing to know any details of the implementation class. I am going to do this by using dependency injection, much as I did in Chapters 23 and 24.
To begin, I have added a reference to the Ninject assembly. This is the same assembly that I used previously, and I included in the source code download for this book. Next I have created a class called CustomDependencyResolver
in a folder called Infrastructure
. Listing 31-9 shows this class.
Listing 31-9. The CustomDependencyResolver class
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Ninject;
using Ninject.Syntax;
using TriathlonApp.Models.Domain.Repository;
namespace TriathlonApp.Infrastructure ...
Get Applied ASP.NET 4 in Context now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.