anshul
anshul

Reputation: 63

ASP.NET MVC 5 application - Repository pattern without Entity Framework

I am trying my hands on creating an ASP.NET MVC 5 app without entity framework. I have some existing database, but do not want to use Entity Framework for that. Came up with simple and uncluttered architecture having Entities, Repository and DAL. I have created a controller passing Repository context to it.

public class EmployeeController : Controller
{
    private readonly IEmployeeRespository repository;

    public EmployeeController(IEmployeeRespository _repository)
    {
        repository = _repository;
    }

    // GET: Employee
    public ActionResult Index()
    {
        IEnumerable<Employee> Employees = repository.GetEmployees();
        return View(Employees);
    }
}

Issue here is, I have not created a parameterless contructor for this controller. Now how do I pass my repository context to this controller. I am missing out some step, but not able to figure out.
Also, if anyone know of any downloadable sample application for such scenario, it will be of great help.

Upvotes: 0

Views: 1605

Answers (2)

Michael G. Workman
Michael G. Workman

Reputation: 375

I looked at using a Repository design pattern to use with an MVC 5 Application I have been working on, but unfortunately it looked like a major rework of my MVC application, basically I would have to start from scratch again with this application. I found it would be far easier to maintain the MVC application by leaving Entity Framework models intact, even though that slows down the MVC application, my resolution is to have the MVC application run in a virtualized server with more computing resources added to speed up the application. more resources from its current level.

Entity Framework Models are far easier to maintain than using a Repository design pattern, if the application is slow because the EF models have many sub-models as virtual properties, that is ok, the easy solution to the problem is to have a more powerful server running the application, more RAM, faster CPU's, more computing resources, etc.

From my point of view, using a Repository adds far more layers of complexity to an application and makes it more difficult to maintain.

Upvotes: 0

DarthVader
DarthVader

Reputation: 55022

Dependency injection is your answer. there are some libraries that will do it for you. You can also do poor-mans injection yourself, or with a service locator.

You can use autofac or ninject that will orchestrate your dependency resolution.

This would help: How do I properly register AutoFac in a basic MVC5.1 website?

Upvotes: 1

Related Questions