Discussion:
Use @Inject inside the module class
vishesh kamdar
2016-08-26 20:51:18 UTC
Permalink
So I'm trying to do something like this inside the Module class


@Inject(optional = true)@Named("TotalQuantity")private int totalQuantity = 5


Is this the correct way to set the default value, if the dependency is not
provided?
--
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/71a4c04c-dd19-4557-ac4c-909c4b2bb74a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
vishesh kamdar
2016-08-26 22:40:34 UTC
Permalink
down votefavorite
<http://stackoverflow.com/questions/39173294/one-can-use-autowired-inside-a-spring-config-but-cannot-use-inject-in-a-guice#>

As far as I can understand, use @Autowired inside a Spring config but
cannot use @Inject in a Guice Module file. Is this true? (JAVA)

I want to use something like this inside the Module class

public class MyModule extends AbstractModule {
@Inject(optional = true)
@Named("TotalQuantity")
private int totalQuantity = 5;

@Provides
@Singleton
Boolean getBoolean()
{
if(totalQuantity>10)
return true;
else
return false;
}

@Override
protected void configure() {}}

Is this the correct way to set the default value, if the dependency is not
provided?
Post by vishesh kamdar
So I'm trying to do something like this inside the Module class
@Inject(optional = true)@Named("TotalQuantity")private int totalQuantity = 5
Is this the correct way to set the default value, if the dependency is not
provided?
--
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/1e869cb7-478a-4b08-abf8-b3e6853bbb16%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Marshall Pierce
2016-08-27 20:20:15 UTC
Permalink
Post by vishesh kamdar
down vote
favorite
I want to use something like this inside the Module class
public class MyModule extends AbstractModule
{
@Inject(optional = true)
@Named("TotalQuantity")
private int totalQuantity = 5;
@Provides
@Singleton
Boolean getBoolean()
{
if(totalQuantity>10)
return true;
else
return false;
}
@Override
protected void configure() {}
}
Is this the correct way to set the default value, if the dependency is not provided?
So I'm trying to do something like this inside the Module class
@Inject(optional = true)
@Named("TotalQuantity")
private int totalQuantity = 5
Is this the correct way to set the default value, if the dependency is not provided?
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
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/1e869cb7-478a-4b08-abf8-b3e6853bbb16%40googlegroups.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/9D3F60A8-811A-4A9F-B576-58AEF472AF37%40mpierce.org.
For more options, visit https://groups.google.com/d/optout.
vishesh kamdar
2016-08-28 08:09:21 UTC
Permalink
Yes, that was the approach I used. Used a Provider Binding. Is there a
better way to handle this?
You probably want to use a Provider (which can take injected constructor
you want to have Guice-injected types as inputs to your module logic.
Post by vishesh kamdar
down vote
favorite
I want to use something like this inside the Module class
public class MyModule extends AbstractModule
{
@Inject(optional = true)
@Named("TotalQuantity")
private int totalQuantity = 5;
@Provides
@Singleton
Boolean getBoolean()
{
if(totalQuantity>10)
return true;
else
return false;
}
@Override
protected void configure() {}
}
Is this the correct way to set the default value, if the dependency is
not provided?
Post by vishesh kamdar
So I'm trying to do something like this inside the Module class
@Inject(optional = true)
@Named("TotalQuantity")
private int totalQuantity = 5
Is this the correct way to set the default value, if the dependency is
not provided?
Post by vishesh kamdar
--
You received this message because you are subscribed to the Google
Groups "google-guice" group.
Post by vishesh kamdar
To unsubscribe from this group and stop receiving emails from it, send
<javascript:>.
Post by vishesh kamdar
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/1e869cb7-478a-4b08-abf8-b3e6853bbb16%40googlegroups.com.
Post by vishesh kamdar
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/754f6537-6cf0-473d-9dc0-a5048d010fb5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...