Entity framework 使用实体框架在引用的dll中使用存储库
我已经创建了一个DLL,其中包含许多身份验证和用户管理,我正试图在一个单独的项目(MVC3网站)中使用这些内容 现在这显然行不通,这是可以理解的 我需要的是依赖注入吗?Entity framework 使用实体框架在引用的dll中使用存储库,entity-framework,asp.net-mvc-3,Entity Framework,Asp.net Mvc 3,我已经创建了一个DLL,其中包含许多身份验证和用户管理,我正试图在一个单独的项目(MVC3网站)中使用这些内容 现在这显然行不通,这是可以理解的 我需要的是依赖注入吗? 在这种情况下,基本代码将如何查找它? 我是否需要在引用的DLL的构造函数中添加一些内容?尝试如下构造控制器: public class TestController : Controller { IAuthenticationRepository AuthenticationRepository
在这种情况下,基本代码将如何查找它?
我是否需要在引用的DLL的构造函数中添加一些内容?尝试如下构造控制器:
public class TestController : Controller
{
IAuthenticationRepository AuthenticationRepository { get;set; }
public void TestController (IuthenticationRepository authenticationRepository)
{
this.AuthenticationRepository = authenticationRepository;
}
public ActionResult Index()
{
this.AuthenticationRepository.DeleteUser(1);
return View();
}
}
为您的存储库创建一个接口。然后,您可以使用DI框架(如Ninject for MVC 3)将AuthenticationRepository的实例注入到IAAuthenticationRepository的使用中
public class TestController : Controller
{
IAuthenticationRepository AuthenticationRepository { get;set; }
public void TestController (IuthenticationRepository authenticationRepository)
{
this.AuthenticationRepository = authenticationRepository;
}
public ActionResult Index()
{
this.AuthenticationRepository.DeleteUser(1);
return View();
}
}