0

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.

3
  • Your code loook correct and definetely it's not about EF. Commented Oct 31, 2015 at 8:13
  • maybe if you include an error message it would help.... yeah as DarthVader said your looking for some sort of DI, to do what you are wanting. Commented Oct 31, 2015 at 8:26
  • @Seabizkit yeah that was the problem. i had not implemented DI. Used unity for it and worked fine now. Commented Oct 31, 2015 at 9:33

2 Answers 2

1

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?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanx. I was missing out just this. I used Unity for dependency injection. And it worked smoothly.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.