I just needed some kind of feedback / help on how I deal with the architecture of my application. My current decision structure looks something like this:
- UI (Actual MVC Application)
- Kernel (controllers and ViewModels only)
- Services
- Bll
- Data (Entity DbContext infrastructure bound to Domain objects)
- Domain (simple POCO objects)
- Interfaces
Other things
- Ninject to enter DbContext into the controller (for each request)
- AutoMapper to display domain objects in ViewModel
All assemblies have a link to the "Interfaces" project, which, as the name implies, is nothing more than simple interfaces (i.e. IDbContext, IRepository, etc.).
The Services project links everything else. This is the only assembly that has a direct link to the Entity Framework.
I have provided the code below:
An example controller looks like this:
namespace Core.Controllers { public class HomeController : Controller { private IDbContext dbContext; public HomeController(IDbContext dbContext) { this.dbContext = dbContext; } public ActionResult Users() { UserService userService = new UserService(dbContext); var users = userService.GetAllUsers(); return View(Mapper.Map<IEnumerable<UserListViewModel>>(users)); } ...
UserService Class:
namespace Services { public class UserService { private readonly IDbContext dbContext; public UserService(IDbContext dbContext) { this.dbContext = dbContext; } public IEnumerable<User> GetAllUsers() { IRepository<User> userRepository = new Repository<User>(dbContext); UserBLL userBLL = new UserBLL(userRepository); return userBLL.GetAllUsers(); } ...
Finally, a business level class:
namespace BLL { public class UserBLL { private readonly IRepository<User> userRepository; public UserBLL(IRepository<User> userRepository) { this.userRepository = userRepository; } public IEnumerable<User> GetAllUsers() { return userRepository.Get(); } ...
I am looking for some feedback / ways to improve. I notice that for basic tasks, my service-level methods will be exactly the same as the business-level methods (ie, Skip). I hope this abstraction will be useful for more complex tasks that may require calls to several business-level methods. Would it be better to incorporate business logic into the service level?
user1513044
source share