Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jose Marcenaro 10 posts 111 karma points c-trib
    Jul 10, 2021 @ 11:07
    Jose Marcenaro
    0

    How to change Default Controller Type in V9

    In Umbraco v9 beta versions there was a way to override the default controller type by issuing:

    builder.Services.Replace(new ServiceDescriptor(
                typeof(IUmbracoRenderingDefaults), typeof( MyUmbracoRenderingDefaults ), ServiceLifetime.Singleton));
    

    But the IUmbracoRenderingDefaults interface is gone in rc-001 and I can't find the correct way to override the default controller type.

    Thanks in advance.

  • Marc Goodson 1577 posts 10543 karma points MVP 6x c-trib
    Jul 11, 2021 @ 17:31
    Marc Goodson
    1

    Hi Jose

    Think this has been updated for RC001 to use IOptions pattern...

    You can assign a default RenderController to be a custom implementation by updating the options for UmbracoRenderingDefaultsOptions in the ConfigureServices method in the Startup.cs class.

    First of all you have to create your own controller. Your custom implementation of RenderController should either inherit from the core RenderController as in the examples above or implement the IRenderController interface.

    Once you've created your controller then you now use the DefaultRenderController extension method in the ConfigureServices method in the Startup.cs class. (call SetDefaultRenderController method after the AddWebsite method)

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddUmbraco(_env, _config)
            .AddBackOffice()             
            .AddWebsite()
            .SetDefaultRenderController()
            .AddComposers()
            .Build();
    
        // Configure Umbraco Render Controller Type
        services.Configure<UmbracoRenderingDefaultsOptions>(c =>
        {
            c.DefaultControllerType = typeof(MyRenderController);
        });
    }
    
  • Jose Marcenaro 10 posts 111 karma points c-trib
    Jul 12, 2021 @ 10:39
    Jose Marcenaro
    0

    Hi Marc,

    Thanks for taking the time to explaining this IOptions pattern. Using services.Configure<>() as you describe solves my problem.

    I found one difference, though: it looks like the .SetDefaultRenderController() extension you mention does not exist in v9.0.0-rc001 ...nor it is required, because the solution works without that line - just using services.Configure<>() does the trick and sets the default render controller.

    A google search for the missing method got me to this discussion which seems to confirm the fact that the method is not required.

    Can you please clarify that point before I mark your response as the solution?

    Thanks again!

  • Marc Goodson 1577 posts 10543 karma points MVP 6x c-trib
    Jul 12, 2021 @ 11:24
    Marc Goodson
    1

    Hi Jose

    Thanks for trying it out and reporting back!

    Yes you are correct SetDefaultRenderController() is no longer required...

    enter image description here

    In the eagerness to document things! the SetDefaultRenderController() extension method got added to some draft documentation, but then got switched to IOptions approach - which we then updated, but didn't take out the extension method!!!

    I'll update the docs page accordingly.

    But hopefully that aleviates your immediate concerns!

    thanks

    Marc

  • Marc Goodson 1577 posts 10543 karma points MVP 6x c-trib
    Jul 12, 2021 @ 11:26
  • Keith 18 posts 101 karma points
    Jul 12, 2021 @ 22:12
    Keith
    0

    :) Thanks

Please Sign in or register to post replies

Write your reply to:

Draft