身份驗證類應該是靜態的還是從實例創建的?身份驗證類應該是靜態的還是從實例創建的?
我有的問題是,我不能訪問身份驗證,而無需在任何控制器中注入它的實例,並且有點問題。
public class HomeController : Controller
{
//=> I WANT TO AVOID THIS! <=
//protected IAuthentification Authentification { get; private set; }
//public HomeController(IAuthentification authentification)
//{
// Authentification = authentification;
//}
public ActionResult Index()
{
//Authentification.CreerUtilisateur(new Utilisateur { Nom = "Test", NomUsage = "ttt", MotDePasse = "ddsss" });
return View();
}
}
可能的重複[如何處理與Ninject靜態方法的類?](http://stackoverflow.com/questions/2710718/how-do-i-handle-classes-with-static-methods-with- ninject) –