dagger icon indicating copy to clipboard operation
dagger copied to clipboard

Support generic modules

Open christopherperry opened this issue 11 years ago • 1 comments

I have a lot of boilerplate because I can't use generics with my module classes.

A contrived example:

@Module
public class ShapeModule<T> {
    @Provides Shape<T> provideShape() {
        return new Shape<T>();
    }
}

ObjectGraph.create(new ShapeModule<Square>(), new ShapeModule<Circle>(), new ShapeModule<Rectangle>());

so I'm forced to do:

@Module
public class SquareModule {
    @Provides Shape<Square> provideShape() {
        return new Shape<Square>();
    }
}

@Module
public class CircleModule {
    @Provides Shape<Circle> provideShape() {
        return new Shape<Circle>();
    }
}

@Module
public class RectangleModule {
    @Provides Shape<Rectangle> provideShape() {
        return new Shape<Rectangle>();
    }
}

ObjectGraph.create(new SquareModule(), new CircleModule(), new RectangleModule());

I'm forced to create a module for every type!

christopherperry avatar Mar 17 '14 21:03 christopherperry

You are not forced to create a module for every type but a @Provides method for every type.

thatsIch avatar Mar 23 '14 12:03 thatsIch