mercredi 6 février 2019

Software design - compilation time validation of type in a spring @Configuration file

Let's say I have the following configuration class as follows:

@Configuration
class Config{
    @Autowired F factory;

    @Bean
    public S stream(){
        return new S(factory);
    }

    @Bean
    public M model(@Autowired S stream){
        return new M'(stream);
    }
}

I have many of these configurations. One for each "model" I'm building. Each configuration has a factory, a stream, and the final model.

When adding a new configuration file like this, I want to validate, in compilation time, that when using a model of type M', I also use a stream which uses a factory of type F'.

I think I can easily do it by having an additional parameter in the constructor of M' that will require an F'. But, IMO it will be ugly, since M' doesn't use the factory at all...

Any thought of an elegant way to force this in compilation time?

Aucun commentaire:

Enregistrer un commentaire