MVC 4 Autofac and Generic Repository pattern

后端 未结 1 928
日久生厌
日久生厌 2021-02-07 12:08

I am utilizing the Unit Of Work and Generic Repository pattern in my MVC 4 app. The problem I am trying to solve is creating Repository stubs for every entity in my system. In o

1条回答
  •  滥情空心
    2021-02-07 12:39

    You need the open generics feature of Autofac:

    builder.RegisterGeneric(typeof(RepositoryBase<>))
       .As(typeof(IRepository<>));
    

    Then you use your repositories exactly as you described:

    public class SomeService
    {
        private readonly IRepository _repository;
    
        public SchoolService(IRepository repository)
        {
            this._repository= repository;
        }
    }
    

    0 讨论(0)
提交回复
热议问题