我应该在哪里创建实例?哪种方式更好,为什么?
1)在构造函数中?
public class UserController : Controller
{
private UnitOfWork unitofwork;
public UserController(){
unitofwork = new UnitofWork();
}
public ActionResult DoStuff(){
...
2)作为私人班级成员?
public class UserController : Controller
{
private UnitOfWork unitofwork = new UnitofWork();
public ActionResult DoStuff(){
...