1

In my Spring MVC application I have a 'DrawingController' that accepts MultipartHttpRequests from clients.

A user can upload any type of drawing( for the time being only auto cad and bim drawings) from the front end.

There is an interface called 'DrawingService' and two implementations 'BIMDrawingService' and 'CADDrawingService' as follows.

public interface DrawingService{    
    public String manageUpload();
}

 @Component("bimService")
  public class BIMDrawingService implements DrawingService{
    public String manageUpload() {//}
  }

  @Component("cadService")
  public class CADDrawingService implements DrawingService{
    public String manageUpload() {//}
  }

public class DrawingController {
@Autowired
@Qualifier("bimService")
private DrawingService bimService;  

@Autowired
@Qualifier("cadService")
private DrawingService cadService;      

public void setDrawingService(DrawingService bimService) {
    this.bimService= bimService;
}


 @RequestMapping(value = "/upload", method = RequestMethod.POST)
    public @ResponseBody String handleFileUpload(MultipartHttpServletRequest request){
  //if request type == BIM, then ignore the logic how I differentiate
 if bimrequest
    bimService.manageupload()

 else if cadrequest
    cadService.manageupload()
}

I feel this is not the good way to do and my question is how I can inject the services dynamically at run time, even If I add new drawing services later, with the minimal changes I should be able to progress. Please suggest me some best design solution.

Tharsan Sivakumar
  • 6,351
  • 3
  • 19
  • 28

0 Answers0