Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suggest MVC frameworks that do not use controller base classes

Pseudo-code:

class SomeController {
  def myAction() {
    // controler is an property passed via ctor
    controller.redirect(toWhereever)
  }
}

// another variant
class AnotherController {
  def myAction(controller) {
    // controler is an method argument
    controller.redirect(toWhereever)
  }
}

Any suggestions?

Edit: Because the question is a bit dry you could try to spice up your answers with some experience with the framework and what do you think is better with that approach.

like image 537
c0rnh0li0 Avatar asked Sep 05 '26 05:09

c0rnh0li0


1 Answers

Spring MVC and Grails (built ontop of spring) favour dependency injection with no inheritance whatsoever. Each controller is a class that does not extend anything. Instead you can inject other components into it (using dependency-injection). For example:

@Controller
@RequestMapping("/user")
public class UserController {

     @Inject
     private UserService service;

     @RequestMapping("/register")
     public String register(User user) {..}

}

@Controller
@RequestMapping("/orders")
public class OrderController {
     @Inject
     private UserController userController
}

(Although it is not a common practice to inject controllers into other controllers, you can inject any object)

like image 125
Bozho Avatar answered Sep 07 '26 07:09

Bozho



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!