Fallback to use ActivatorUtilities to create controller from type, if it is not registered in DI (#13910)

This commit is contained in:
Bjarke Berg
2023-03-07 11:21:57 +01:00
committed by GitHub
parent 0789bb9eb1
commit e2a15b58ed

View File

@@ -61,8 +61,9 @@ public class UmbracoVirtualPageRoute : IUmbracoVirtualPageRoute
if (controllerType != null)
{
// Get the controller for the endpoint
var controller = httpContext.RequestServices.GetRequiredService(controllerType);
// Get the controller for the endpoint. We need to fallback to ActivatorUtilities if the controller is not registered in DI.
var controller = httpContext.RequestServices.GetService(controllerType)
?? ActivatorUtilities.CreateInstance(httpContext.RequestServices, controllerType);
// Try and find the content if this is a virtual page
IPublishedContent? publishedContent = FindContent(