0

Visual Studio 2015 버전을 사용 중입니다. Nuget에서 통합을 설치했습니다. 내가 의존성 주입 모델을 사용하여 코드를 첫 번째 접근 방식으로 테이블에서 사용자 목록을 얻으려고했습니다. 컨테이너를 등록 할 때 누군가 실수로 컨테이너를 등록 할 수있게 안내 해줄 수 있다고 생각합니다. 이 코드를 실행하려고하면 "이 매개 변수가없는 매개 변수가없는 생성자가 없습니다."와 같은 오류가 표시됩니다. Google에서 솔루션을 많이 찾았지만 Microsoft.practice.unity를 사용하는 unity5와 같은 이전 버전의 유니티를 사용하고 있습니다. 나는 단결 5.1.2 버전을 사용하고 있습니다. 접근 방식이 잘못 되었다면이 코드를 변경하여 단일성으로 작업하십시오. 미리 감사드립니다.mvc5에서 종속성을 사용하여 Unity가 작동하지 않음

내 모델 코드

public class UserInfo 
    { 

     [Key] 
     public int UserID { get; set; } 

     [Required(ErrorMessage = "Please Enter The FirstName")] 
     public string FirstName { get; set; } 

     [EmailAddress(ErrorMessage = "Invalid Email Address")] 
     [Required(ErrorMessage = "Please Enter The Email")] 
     public string Email { get; set; } 
} 

내 인터페이스 코드

public interface IUserInformation 
    { 
     IEnumerable<UserInfo> GetAll(); 
     UserInfo Get(int id); 
     UserInfo Add(UserInfo item); 
     bool Update(UserInfo item); 
     bool Delete(int id); 
    } 

내 저장소 코드

public class UserRepository:IUserInformation 
    { 
     private ProdDBContext db = new ProdDBContext(); 
     LogWriter obj1 = new LogWriter(); 
     public IEnumerable<UserInfo> GetAll() 
     { 
      try 
      { 
       return db.User.ToList(); 
      } 
      catch (Exception ex) 
      { 
       obj1.WriteToFile("Error in User Index repository " + ex.Message); 
       obj1.WriteToFile("Error in User Index repository " + DateTime.Now); 

      } 
      return db.User.ToList(); 

     } 

내 컨트롤러 코드

public class UserInformationController : Controller 
    { 

     private ProdDBContext db = new ProdDBContext(); 
     LogWriter obj1 = new LogWriter(); 
     readonly IUserInformation IuserInf; 

     public UserInformationController(IUserInformation IuserInf) 
     { 
      this.IuserInf = IuserInf; 
     } 
      [CustomFilters] 
      [CustomAuthorize(Roles = "admin")] 
      public ActionResult Index() 
      { 
       try 
       { 
        var Userlist = IuserInf.GetAll(); 
        return View(Userlist); 

       } 
       catch (Exception ex) 
       { 
        obj1.WriteToFile("Error in User Index page" + ex.Message); 
        obj1.WriteToFile("Error in User Index page" + DateTime.Now); 

       } 
       return View(); 
      } 
} 
응용 프로그램에서3210

내 설정 파일은 기본적으로

public UserRepository() { } 

매개 변수가없는 생성자이 비공개 매개 변수가없는 생성자에게없는

public class UnityConfig 
    { 

    private static IUnityContainer BuildUnityContainer() 
    { 
     var container = new UnityContainer(); 


     register all your components with the container here 
     container.RegisterType<IUserInformation, UserRepository>(); 

     return container; 
    } 
} 

마침내 내가

UnityConfig.BuildUnityContainer(); 

답변

0

UserRepository로 내 글로벌 ASCX 코드를 등록 시작 그리고 그 때문에 Unity는 인스턴스를 만들 수 없습니다.

+0

UserRepository 생성자를 추가했지만 동일한 오류가 발생하지 않았습니다. 다른 해결책은 제발 –