Works for me and then I @Inject MyService into the constructor of my resource class.
Sent from my iPhone
> On Jan 30, 2015, at 9:15 PM, Dietz, Randall <randall_at_dietz.id.au> wrote:
>
> Thanks Robert,
>
> I've tried that approach (a variation of it anyway) and still get the following exception:
> org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=ConfigurationManager,parent=UserApiService,qualifiers={},position=-1,optional=false,self=false,unqualified=null,1807772254)
>
> I'm using the following to do the injection:
>
> @Inject
> private ConfigurationManager configurationManager;
>
> If I use @Context instead of @Inject (as per someone elses suggestion), I don't get an exception but the class is not injected.
>
> I can't help but think there's something missing here, is that code below all I should have to do?
> Thanks
>
>> On Saturday, January 31, 2015, Robert DiFalco <robert.difalco_at_gmail.com> wrote:
>> I'm not exactly sure what you are asking but if you have some service that you want to be able to inject into your Resource instances you can just add this to the constructor of your ResourceConfig class:
>>
>> register(new AbstractBinder() {
>> @Override
>> protected void configure() {
>> bind(MyService.getInstance()).to(MyService.class);
>> }
>> });
>>
>>> On Fri, Jan 30, 2015 at 1:11 PM, Dietz, Randall <randall_at_dietz.id.au> wrote:
>>> Hi all,
>>>
>>> Can someone please point me to some up-to-date documentation that has an example of how to add a singleton class to a Jersey (v2.15) REST API?
>>>
>>> I have successfully built a REST application in Jersey, now all I want to do is inject a Singleton class (that controls access to my central configuration) in my service classes that is shared across all requests. Really, really simple use case... but I've wasted hours trying to get it working.
>>>
>>> The problem I've encountered is that there are a number of "solutions" on the InterWeb, but they're either out of date, confusing or just plain wrong.
>>>
>>> Would appreciate some guidance or examples of how it should be done in the latest Jersey.
>>>
>>> Thanks -- Randall