How do I override an entity view controller? I am trying to override the entity view controller for a commerce product view, so that I can  redirect the user based on certain conditions.
I am trying to do this through the RouteSubscriber::alterRoutes implementation.
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    if ($route = $collection-&gt;get('entity.commerce_product.canonical')) {
      $route-&gt;addDefaults(['_controller' =&gt; '\Drupal\mymodule\Controller\ProductViewController::view']);
    }
  }

}

My custom controller is acknowledged, but I'm getting the following error:

RuntimeException: Controller &quot;Drupal\mymodule\Controller\ProductViewController::view()&quot; requires that you provide a value for the &quot;$_entity&quot; argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one. in Symfony\Component\HttpKernel\Controller\ArgumentResolver-&gt;getArguments() (line 78 of /var/www/html/vendor/symfony/http-kernel/Controller/ArgumentResolver.php).

My ProductViewController extends the Drupal\Core\Entity\Controller\EntityViewController.
class ProductViewController extends EntityViewController {

  public function view(EntityInterface $_entity, $view_mode = 'full')
  {
    return parent::view($_entity, $view_mode); 
  }

}

Can anyone tell what additional route context parameters I need to add to get this working?
I think you may be unsetting some things in your alterRoutes method doing it the way you are. (However, I can't tell if or why that's happening after looking at Route::addDefaults().)
I'm doing the same thing for a media entity's route. My alterRoutes method is a little different - I'm using Route::setDefault().
public function alterRoutes(RouteCollection $collection) {
  if ($route = $collection-&gt;get('entity.media.canonical')) {
    $route-&gt;setDefault('_controller', '\Drupal\my_module\Controller\MyController::view');
  }
}

Additionally, the variable names in your controller methods are important - they must match the variable name from the route definition. See the documentation for Using parameters in routes

In most PHP code the name of the variable does not matter but here it does: the name of the method argument must match the slug. Conversely, if the method argument name matches the name of the slug, the parameter will be passed in, irrespective of the order of arguments.