0
我有一個具有存儲庫層和WebUI層的Web應用程序。在Web應用程序中使用靜態方法的正確方法
基本上我用我從這個存儲庫DLL中獲得的數據填充一些網格。其實即時通訊做這樣的:
private DemoRepository _demoRepository;
public DemoController()
{
_demoRepository = new DemoRepository();
}
public ActionResult Demonstration()
{
return View(_demoRepository.GetAll());
}
我的問題是,事實上,我需要創建一個對象每次,所以我可以使DemoRepository靜態和直接在ActionResult的方法調用:
public ActionResult Demonstration()
{
return View(DemoRepository.GetAll());
}
但除此之外,我知道在Web應用程序中使用靜態變量並不是一個好習慣,但在這種情況下,即時執行一個方法來獲取一些數據,這是否正確?
[相關閱讀](http://stackoverflow.com/a/4596323/1283847)。這個問題是關於PHP的,但潛在的原因幾乎與平臺無關。 – Leri