private readonly IPropertyMappingService _propertyMappingService; //依赖与抽象而不是实现,这里依赖注入和下面的容器都必须是接口类型

        public CompanyRepository(Restful_DbContext context, IPropertyMappingService propertyMappingService)
        {
            _context = context ?? throw new ArgumentNullException(nameof(context));
            _propertyMappingService = propertyMappingService ?? throw new ArgumentNullException(nameof(propertyMappingService));
        }
Exemple #2
0
 //再次犯错,这里必须要注入接口类型propertyMappingServiceForTask,容器里必须是接口类型或者抽象服务类
 public EmployeeTaskRepository(Restful_DbContext context, IPropertyMappingServiceForTask propertyMappingServiceForTask)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
     _propertyMappingServiceForTask = propertyMappingServiceForTask ?? throw new ArgumentNullException(nameof(propertyMappingServiceForTask));
 }