PluginController is just a base Controller that other core Controllers inherit from in order to to help with MVC routing and for defining MVC areas using the [PluginController("areaName")] attribute.
Controllers that inherit from PluginController have a GetMetadata method that is used internally in Umbraco to track what kind of Controller the Controller is (backoffice etc) and how it is routed, eg AreaName.
One of the benefits this facilitates is if you were building an Umbraco Package to share with other Umbraco users and it contained a SurfaceController perhaps with the name LoginController it would be highly likely it would clash with an existing controller in someone else's Umbraco site, or another package... by decorating your SurfaceController with the PluginController attribute you can ascribe a hopefully unique name that won't create a clash.
[PluginController("superloginpackage")]
public LoginController : SurfaceController
Would you inherit directly from PluginController?
yes, in the circumstance where you would not want your mvc controller to be auto-routed in the way that a SurfaceController is... eg map a custom mvc route to an MVC Controller without the context of a current request... but that is quite a niche circumstance... but useful to know about!
but these days you would more likely use Route Hijacking by Doc Type to handle an incoming route by convention inheriting from RenderMvcController or by custom route using a VirtualNodeRouteHandler to associate a custom IPublishedContent item with the request:
Use-cases for PluginController
So there are a bunch of different kind of base Controller classes in Umbraco, all of which have their purpose:
But there is also PluginController (not the attribute), on which the SurfaceController is based.
I was wondering if there are any use-case to ever directly extend PluginController?
Hi Lennard
PluginController is just a base Controller that other core Controllers inherit from in order to to help with MVC routing and for defining MVC areas using the [PluginController("areaName")] attribute.
https://github.com/umbraco/Umbraco-CMS/blob/v8/contrib/src/Umbraco.Web/Mvc/PluginController.cs
Controllers that inherit from PluginController have a GetMetadata method that is used internally in Umbraco to track what kind of Controller the Controller is (backoffice etc) and how it is routed, eg AreaName.
One of the benefits this facilitates is if you were building an Umbraco Package to share with other Umbraco users and it contained a SurfaceController perhaps with the name LoginController it would be highly likely it would clash with an existing controller in someone else's Umbraco site, or another package... by decorating your SurfaceController with the PluginController attribute you can ascribe a hopefully unique name that won't create a clash.
Would you inherit directly from PluginController?
yes, in the circumstance where you would not want your mvc controller to be auto-routed in the way that a SurfaceController is... eg map a custom mvc route to an MVC Controller without the context of a current request... but that is quite a niche circumstance... but useful to know about!
This article from 'back in the day' explains a little about the emergence of that approach: https://shazwazza.com/post/custom-mvc-routing-in-umbraco/
but these days you would more likely use Route Hijacking by Doc Type to handle an incoming route by convention inheriting from RenderMvcController or by custom route using a VirtualNodeRouteHandler to associate a custom IPublishedContent item with the request:
https://our.umbraco.com/documentation/reference/routing/custom-routes
regards
Marc
Thanks Marc, was indeed suspecting it was very niche to do. Thanks for the link to Shannon's blog post!
is working on a reply...