Whenever I develop an MVC application there is always some degree of data access required. As a best practice, I usually define a interface that my repository objects will adhere to. Creating an interface is generally a requirement for Dependency Injection (DI). DI is a very important pattern if you plan on doing any unit testing later on. For the purpose of this demo, I am going to keep things simple and only create a fake repository. Here is the code: public interface IRepository
{
Person GetPerson( int id );
}
public class FakeRepository : IRepository
{
public Person GetPerson( int id )
{
return new Person { Id = id, FirstName = "Mike", LastName = "Ceranski" };
}
}
Obviously, in a real-world application you would probably utilize the Entity Framework or LINQ to SQL in order to implement the IRepository interface. However, for the purposes of this demo the FakeRepository illustrates the point. Moving on, the n...
[More]