0

I am trying to inject a io.micronaut.runtime.http.scope.RequestScope object into my jaxrs resource. Here I am priting object to see if it creates different objects for each request. But the object created Only once, even when I sent multiple requests. Is this a known issue ? Any other way to work around this if that's the case.

@RequestScope
public class RequestScopeObjectX {

    public RequestScopeObjectX() {
        System.out.println("-------------------------"+this);
    }
}

And in. my jaxrs resource class I am doing injecting it

@Inject
RequestScopeObjectX objectX;
Subash Chaturanga
  • 814
  • 2
  • 10
  • 20
  • Too little code to tell, but how many times is the constructor for the class that is hosting the injected instance called? Might be related to this issue: https://github.com/micronaut-projects/micronaut-core/issues/1615 – Roar S. Jul 27 '22 at 13:08
  • 1
    This is working as expected. Only I was testing in incorrect way. Like checking injected object hash code to be different. Turns out that’s a proxy being injected and read object is actually creating for every request. – Subash Chaturanga Aug 08 '22 at 14:36
  • Maybe just delete this question because it is resolved? BR – Roar S. Aug 08 '22 at 18:05

0 Answers0