Discussion:
How to create/bind singleton object of 3rd party class which has 2 argument constructor. I need to pass 2 singleton object in the constructor
Akash Patel
2017-01-21 19:23:05 UTC
Permalink
I have 3rd party API and i need to inject that api object as singleton
through google juice. That class has 2 argument constructor and i need to
pass 2 argument (Both are object) from my api.

Similar to this


GetTemplate getTemplate = new GetTemplate(new PluginRegistory(),

new
DefaultExceptionHandler());


GetTemplate is 3rd party api class and i need to pass my 2 implementation
of PluginRegistory and DefaultExceptionHandler. How i can do this with
google guice? I was doing it with spring by "constructor-args"
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/9c698b1f-704a-4e61-b931-39d82fba4ad2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Olivier Grégoire
2017-01-21 19:47:45 UTC
Permalink
I think this would have better been asked on Stack Overflow, but still
here's an answer:


public class MyModule extends AbstractModule {
@Override protected void configure() {
// Normal bindings
}

@Provides
// @Singleton
GetTemplate provideGetTemplate(PluginRepository pluginRepository,
ExceptionHandler exceptionHandler) {
return new GetTemplate(pluginRepository, exceptionHandler);
}
}
Post by Akash Patel
I have 3rd party API and i need to inject that api object as singleton
through google juice. That class has 2 argument constructor and i need to
pass 2 argument (Both are object) from my api.
Similar to this
GetTemplate getTemplate = new GetTemplate(new PluginRegistory(),
new
DefaultExceptionHandler());
GetTemplate is 3rd party api class and i need to pass my 2 implementation
of PluginRegistory and DefaultExceptionHandler. How i can do this with
google guice? I was doing it with spring by "constructor-args"
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/9c698b1f-704a-4e61-b931-39d82fba4ad2%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/9c698b1f-704a-4e61-b931-39d82fba4ad2%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/CAORw%3DcOig6D-000hNvhXJ8HjBJSottnMgbdpnL83tDWho3bNTg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Stephan Classen
2017-01-21 22:06:01 UTC
Permalink
Or simply:
bind(GetTemplate.class).toInstance(new GetTemplate(...));
Post by Olivier Grégoire
I think this would have better been asked on Stack Overflow, but still
public class MyModule extends AbstractModule {
@Override protected void configure() {
// Normal bindings
}
@Provides
GetTemplate provideGetTemplate(PluginRepository pluginRepository,
ExceptionHandler exceptionHandler) {
return new GetTemplate(pluginRepository, exceptionHandler);
}
}
Post by Akash Patel
I have 3rd party API and i need to inject that api object as
singleton
Post by Akash Patel
through google juice. That class has 2 argument constructor and i
need to
Post by Akash Patel
pass 2 argument (Both are object) from my api.
Similar to this
GetTemplate getTemplate = new GetTemplate(new PluginRegistory(),
new
DefaultExceptionHandler());
GetTemplate is 3rd party api class and i need to pass my 2
implementation
Post by Akash Patel
of PluginRegistory and DefaultExceptionHandler. How i can do this
with
Post by Akash Patel
google guice? I was doing it with spring by "constructor-args"
--
You received this message because you are subscribed to the Google
Groups
Post by Akash Patel
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it,
send an
Post by Akash Patel
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/9c698b1f-704a-4e61-b931-39d82fba4ad2%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/9c698b1f-704a-4e61-b931-39d82fba4ad2%40googlegroups.com?utm_medium=email&utm_source=footer>
Post by Akash Patel
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/CAORw%3DcOig6D-000hNvhXJ8HjBJSottnMgbdpnL83tDWho3bNTg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/56E41653-BE5F-49A4-B7B7-D565B676C99F%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.
Akash Patel
2017-01-23 07:12:36 UTC
Permalink
Thanks. That works for me. I am posting the same question on the
stackoverflow so that it will have good visibility for others.
Post by Olivier Grégoire
I think this would have better been asked on Stack Overflow, but still
public class MyModule extends AbstractModule {
@Override protected void configure() {
// Normal bindings
}
@Provides
GetTemplate provideGetTemplate(PluginRepository pluginRepository,
ExceptionHandler exceptionHandler) {
return new GetTemplate(pluginRepository, exceptionHandler);
}
}
Post by Akash Patel
I have 3rd party API and i need to inject that api object as singleton
through google juice. That class has 2 argument constructor and i need to
pass 2 argument (Both are object) from my api.
Similar to this
GetTemplate getTemplate = new GetTemplate(new PluginRegistory(),
new
DefaultExceptionHandler());
GetTemplate is 3rd party api class and i need to pass my 2 implementation
of PluginRegistory and DefaultExceptionHandler. How i can do this with
google guice? I was doing it with spring by "constructor-args"
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an
<javascript:>.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/9c698b1f-704a-4e61-b931-39d82fba4ad2%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/9c698b1f-704a-4e61-b931-39d82fba4ad2%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/5bb9fd4c-c8b1-4413-b1be-fe163e8129ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...