0

I am new to jax-rs and dependency injection, in my application I have a situation where a class uses a DAO object. I have an interface for the DAO and an implementation. I am trying to inject the DAO object inside this class BusinessLogic using @Context in jax-rs.

Ex:

Class BusinessLogic{
@Context
BackDAO backDAO;

public void doSomethig(){
backDAO.doSome()....
 }
}

where BackDAO is the interface and its implementation is BackDAOImpl.

I want to know how to inject BackDAOImpl object instance here or is it possible to inject User-defined classes using @Context, because as far as my research I think @Context is used on ServletConfig, ServletContext, HttpServletRequest and HttpServletResponse.

I don't want to do this with any frameworks and also without using @Inject, is it possible? I tried many links at stack-overflow and the javadocs didn't have any good examples. Where do @Context objects come from

Community
  • 1
  • 1
user3897395
  • 103
  • 1
  • 1
  • 9
  • What dependency injection framework are you using? `@Context` is typically reserved for internally managed JAX-RS objects. – John Ament Aug 05 '14 at 10:54
  • I am using Jersey RESTful Web Services framework running on GlassFish .I got to do Dependency Injection using Inject and binding the service using AbstractBinder.But I want to know is there any way possible to do the same using Context.Like you suggested @John,As far as my research goes I learned that it supports JAX-RS Object,but I saw in many post on stack-overflow where people ask for solution using Context.Like here: – user3897395 Aug 05 '14 at 14:23
  • @user3897395 - What exactly do you have against using `@Inject`? – kolossus Aug 05 '14 at 21:16
  • @kolossus ,nothing against it.i have implemented using Inject .I wanted to know whether it is possible to do the same using context.I was looking at this post http://stackoverflow.com/questions/10897933/where-do-context-objects-come-from,but I couldnt figure it out – user3897395 Aug 05 '14 at 21:58

0 Answers0