Java Spring工厂依赖于其他工厂

时间:2020-01-16 08:28:12

标签: java spring

我有spring工厂,列出了实现任何接口的类:

@Service
public class ProjectServiceFactory{

    private List<IProjectService> projectServiceList;

    @Autowired
    public ProjectServiceFactory(List<IProjectService> projectServiceList){
        this.projectServiceList= projectServiceList;
    }

    public IProjectService provide(ProjectType projectType){
        Optional<IProjectService> service = this.projectServiceList.stream().filter(projectService-> projectServiceList.isTypeHandler(projectType)).findFirst();
        return service.get();
    }
}

IProjectService的每个实现都依赖于其他接口的不同实现-名为IEntitiesDao。例如-请参阅实现的构造函数之一:

@Service
public class CorrectionsProjectService implement IProjectService {

    @Autowired
    public CorrectionAssignmentsRiskCalculator(IEntitiesDao entitiesDao){
        super(entityListDao);
    }

    //class code...
}

所以我需要Spring注入projectServiceList中的每个元素-IEntitiesDao的其他实现。 我还有另一个工厂-EntitiesDaoFactory,它知道要通过ProjectType枚举返回匹配实现。 但是我应该在哪里叫第二工厂?

0 个答案:

没有答案
相关问题