I’m trying to find out the best way to doing this code
(because I think, my way locks not good):
I’ve tried to make it as easy to understand the problem.
public ActionResult Index()
{
var user=new User();
user.load(1);
return View(user);
}
load(int id )
{
//pseudocode:
//1. load user from repository1
//2. load address from repository2
//3.load payments from repository3
}
Here you go
We would first create a
UserModelServiceas belowWe would then modify the original code in controller as below
All the remaining code reference above is as below
Now in your controller action, instead of creating a new instance of
UserModelService, you can have it injected through constructor. Similar principle can be applied to inject the repositories intoUserModelServicebut that would be another big discussion so I would cut myself short here.