umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
MIT License
4.42k stars 2.67k forks source link

Custom RenderController not injected into pipeline when created from a package #11676

Closed ZioTino closed 1 year ago

ZioTino commented 2 years ago

Which exact Umbraco version are you using? For example: 9.0.1 - don't just write v9

9.0.1

Bug summary

In Umbraco v8 it was possible to create a RenderMvcController from a package, making it available when you install that package in Umbraco.

This is not possible in v9. as the RenderController created from the package is completely ignored.

Specifics

No response

Steps to reproduce

Expected result / actual result

The RenderController must be picked up from the package and injected into the pipeline, as it was with the old behavior from v8.

bergmania commented 1 year ago

Hi @ZioTino

Sorry for the ridiculously late answer 🙈

This is actually by design. No custom render controllers are picked up my magic anymore. You will need to specify the one to use. Like in this example, which can be done from a package.

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Web.Common.Controllers;
using Umbraco.Cms.Web.Website.Controllers;

namespace MyPackage
{
    public class CustomRenderControllerComposer : IComposer
    {
        public void Compose(IUmbracoBuilder builder)
        {
            builder.Services.Configure<UmbracoRenderingDefaultsOptions>(c =>
            {
                c.DefaultControllerType = typeof(MyRenderController);
            });
        }
    }

    public class MyRenderController : RenderController
    {
        public MyRenderController(ILogger<RenderController> logger, ICompositeViewEngine compositeViewEngine, IUmbracoContextAccessor umbracoContextAccessor) : base(logger, compositeViewEngine, umbracoContextAccessor)
        {
        }

        public override IActionResult Index()
        {
            ViewData["TheMeaningOfLifeTheUniverseAndEverything"] = 42;
            return base.Index();
        }
    }
}
dawoe commented 1 year ago

@bergmania you are referencing to setting a default controller. That always had to be explicitly registered. But @ZioTino is talking about route hijacking for a specific doctype.

But to make it short, this works as expected in V10 and V11.