There are times when you need to execute a method on a controller before every action and sometimes on multiple controllers. In my case I had to check that a user was associated with a particular company and if so, fetch the company and some related data from the database. This had to happen before every action in the controller. It also had to happen in several controllers. Rather than extending a common controller class and calling a method from every action I decided to imitate the old symfony1 behavior of the preExecute method.
First, I created an interface. I wanted to be able to implement this interface on any controller that needed to be initialized without adding any extra code or configuration. In my case I always need access to the request and the security context so I specified that here.
Next I implemented this interface on one of my controllers. In it, I get the user and assign to a property. I also check that the user is assigned to a company and throw an error otherwise.
The next step is to create an event listener that checks the controller being called to see if it implements our initializable interface and if so to execute the initialize method.
We now have to attach that event listener to the kernel.controller event.
Now any time we need to execute a method before every action in a controller we simply implement the InitializableControllerInterface.