0
我有一個信息庫,接口,控制器....這看起來是這樣的..具有接口和DI - 不知道是否使用或不? ..Asp.Net MVC 3
接口 - IUSER
public interface IUserRepositories
{
bool CreateUser(User newUser);
bool CheckUniqueEmail(string Email);
bool CheckUserLoginDetails(string email, string password);
}
User Repository
=============
which is implementing all the methods ..
1) CreateUSer
2) CheckLoginDetails
3) CheckUniqueEmail
控制器 - 不知道它做什麼...
private IUserRepositories _userRepo;
public UserController() : this(new UserRepositories())
{
}
public UserController(IUserRepositories userRepo)
{
this._userRepo = userRepo;
}
這看起來不錯......如果是......什麼好處,我可以通過實施這種方式得到...
請從去年3小時解釋...混亂我們....
謝謝...
我試過這個......但是當我運行該應用程序時,它會拋出異常「沒有參數的構造發現」... –
@ patel.milanb,好吧,您必須使用DI框架工作。他們中有很多人。只需選擇一個適合你,但它真的無關緊要你的代碼的其餘部分。 DI框架通常完全獨立配置。 –
這是偉大的......我力知道,我將不得不使用DI框架是....現在我知道我在哪裏缺乏再次... THX ...我想我會用StructureMap爲..看起來很簡單,我.. –