namespace MyApp.Presentation { public class MyController { private readonly MyService _service; public MyController(MyService service) { _service = service; } public IActionResult Get(int id) { var data = _service.GetById(id); var viewModel = new MyViewModel(data); return View(viewModel); } } }
namespace MyApp.Business { public class MyService { private readonly MyRepository _repository; public MyService(MyRepository repository) { _repository = repository; } public MyData GetById(int id) { var data = _repository.Get(id); //do some validation or business logic here return data; } } }
namespace MyApp.Data { public class MyRepository { private readonly MyDbContext _dbContext; public MyRepository(MyDbContext dbContext) { _dbContext = dbContext; } public MyData Get(int id) { return _dbContext.MyData.Find(id); } } }Package/Library: Entity Framework Core, Dapper, NHibernate, etc.