Guice Beginner - How to bind concrete classes?

后端 未结 3 620
庸人自扰
庸人自扰 2021-02-01 13:13

I have this class:

public class House {
    private final Door door;
    private final Window window;
    private final Roof roof;

    @Inject
    public House(         


        
3条回答
  •  独厮守ぢ
    2021-02-01 13:47

    Guice's Just-In-Time binding does exactly what you want. Given your Door, Window and Roof meet following requirements (quoted from the Guice documentation):

    either a public, no-arguments constructor, or a constructor with the @Inject annotation

    an empty Module implementation will be sufficient:

    public class HouseModule extends AbstractModule {
        @Override
        protected void configure() {
        }
    }
    

提交回复
热议问题