Your service can receive other bindings by having them injected into its
constructor.  If the class is defined as:
 class  SomeService {
   @Inject SomeService(Settings settings) { ... }
 }

.. then when others inject the service, Guice will create it with the
correct dependencies for you.

Is there some reason you're unable to inject the parameters directly into
the constructor (and are forced to use 'new')?

 sam


On Fri, Mar 7, 2014 at 5:44 PM, Mikkel Petersen <[email protected]> wrote:

> Because I want to receive other bindings:
> public Service someService(@Inject Settings settings)  {
>   SomeService s =  new SomeService(settings.getHost())
>   inj.injectMembers(s)
>   return s
> }
>
>
>
>
> Den fredag den 7. marts 2014 23.32.42 UTC+1 skrev Nate Bauernfeind:
>>
>> What about your use case prevents you from using a normal .to binding?
>>
>> bind(SomeService.class).to(SomeService.class)
>>
>> Nate
>>
>>
>> On Fri, Mar 7, 2014 at 4:13 PM, Mikkel Petersen <[email protected]> wrote:
>>
>>> Hello all
>>>
>>> I have a slight problem with guice injection when using a method
>>> annotated with  @Provides
>>>
>>> example :
>>>
>>> @Provides
>>> public Service someService() {
>>>  return new SomeService()
>>> }
>>>
>>> I would like to get the current context injected in SomeService..I don't
>>> understand why Guice doesn't do that automatically, any particular reason
>>> for that ?
>>>
>>> I know I could do something like this (it works):
>>>
>>> @Provides
>>> public Service someService(@Inject Injector inj)  {
>>>   SomeService s =  new SomeService()
>>>   inj.injectMembers(s)
>>>   return s
>>> }
>>>
>>> But there must be a simpler way.
>>>
>>> Thanks
>>>
>>> Ps, another question, how to add syntax highlighting ?
>>>
>>>
>>>
>>>
>>>
>>>  --
>>> 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 [email protected].
>>> To post to this group, send email to [email protected].
>>>
>>> Visit this group at http://groups.google.com/group/google-guice.
>>> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/google-guice.
> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/d/optout.

Reply via email to