Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework 使用实体框架在引用的dll中使用存储库_Entity Framework_Asp.net Mvc 3 - Fatal编程技术网

Entity framework 使用实体框架在引用的dll中使用存储库

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,其中包含许多身份验证和用户管理,我正试图在一个单独的项目(MVC3网站)中使用这些内容

现在这显然行不通,这是可以理解的

我需要的是依赖注入吗?
在这种情况下,基本代码将如何查找它?

我是否需要在引用的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();
        }
    }