Move ApplicationDbContext tfrom Role Controller to Service Layer

by w0051977   Last Updated September 13, 2017 12:05 PM

I am creating a role controller to perform CRUD operations on ASP.NET Identity roles. For example, see the code below:

[Authorize(Roles = "Administrator")]
    public class RoleController : Controller
        ApplicationDbContext context;

        public RoleController()
            context = new ApplicationDbContext();

        public ActionResult Index()
            var Roles = context.Roles.ToList();
            return View(Roles);

I am debating whether to move the logic that performs the actual CRUD operation on the database to the service layer (RoleService class). If I did this, then the methods in the controller above would simply call the service layer to perform the CRUD operations. The ApplicationDbContext would be moved to the service layer.

The reason I am thinking about doing this is to be consistent with the rest of the application i.e. using the service layer to access the database.

Related Questions

Domain model design

Updated July 23, 2016 08:02 AM

What is a domain?

Updated October 23, 2017 18:05 PM