MVC 4 Autofac and Generic Repository pattern

后端 未结 1 929
日久生厌
日久生厌 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<SomeEntity> _repository;
    
        public SchoolService(IRepository<SomeEntity> repository)
        {
            this._repository= repository;
        }
    }
    
    0 讨论(0)
提交回复
热议问题