bind()
and bindFactory()
are methods in the AbstractBinder
class that you use to bind your services in the registry. The AbstractBinder
is what you register with Jersey so that it knows to configure all your bindings. You use bind()
to bind the service itself. You use bindFactory()
to bind the service using a Factory
(or Supplier
in 2.26+) to create the service.
RequestScoped
means that the service is scoped to the request, meaning that it will be the same instance for the lifetime of the request. You would use this scope when the service is dependent on information tied to a request, like request headers.
Singleton
scope means that there will only be one instance of the service for the lifetime of the application. You would use this scope when the service can safely be used at anytime without being tied to any request.
PerLookup
means that a new instance of the service will be created every time it is looked up, either directly through the ServiceLocator
(or InjectionManager
in 2.26+) or via an @Inject
(or other injection) annotation. Even though this is the default scope, the RequestScope
and Singleton
scope would be more appropriate for most of the use cases in the context of a Jersey application.
For your use case where you want to get information from the request context and use it in the service, you would use a RequestScoped
service and use a bindFactory()
with a Factory
(or Supplier
in 2.26+) and inject the request context into the Factory
and use the context to create your service. You can see more explanation in How to inject an object into jersey request context?. If you are using Jersey 2.26+, you'll also want to read Jersey 2.26: register @Inject in ResourceConfig bindFactory cannot convert Factory to Supplier