Skip to content

Inject: Example to use Constructor in Module without instance.. #259

Discussion options

You must be logged in to vote

Hi, @narcoticfresh

I do not quite get the part where you need to create the binding without using/referencing the instance itself, but we actually have an example for injecting a class using an interface dependency. The example is not featured on a website, we will add it to the website documentation soon.

Take a look at the Application class. It has a single dependency to the MessageSender interface. In ApplicationModule we configure the required bindings. First binding is:

bind(MessageSender.class).to(ConsoleMessageSenderImpl.class);

We instruct the injector that whenever the MessageSender interface is required, we would actually use a ConsoleMessageSenderImpl implementation.

Another bi…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by narcoticfresh
Comment options

You must be logged in to vote
2 replies
@eduard-vasinskyi
Comment options

@narcoticfresh
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants