What is the usual practice to instantiate domain objects? Suppose in an architecture like following:
@RestController
public class MyController implements ServletConfigAware {
private ApplicationContext context;
@RequestMapping(value="/getNewObject")
public MyBusinessObject getANewObject(){
MyService service = (MyService)context.getBean("myService);
return service.getNewObject();
}
public class MyService {
private ApplicationContext context;
public MyBusinessObject getNewObject(){
return new MyBusinessObject();
vs
(MyBusinessObject)context.getBean("myBusinessObject");
vs
(MyBusinessObject)context.getBean("myBusinessObjectFactory").createNewMyBusinessObject(); //Factory is another class which returns a 'new' object
}
}
public class MyBusinessObject { }
Am I using the spring IOC in intended way?