Copied to clipboard

Flag this post as spam?

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


  • Damiaan 442 posts 1302 karma points MVP 6x c-trib
    Nov 12, 2015 @ 00:31
    Damiaan
    0

    override defaultUrlProvider not working when new constructor is used

    Hi

    When using a custom URL provider in 7.3+ I get a compiler message that DefaultUrlProvider.DefaultUrlProvider() constructor is obsolete. It tells me also to add the constructor with the IRequestHandlerSection parameter.

    So, I have added the constructor as below:

    public MyUrlProvider(IRequestHandlerSection requestSettings)
        : base(requestSettings)
    {  }
    

    But after doing this my method "GetUrl" is never called again.

    public override string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode)
    {
                  // never called again after adding the constructor
    }
    

    I am pretty sure I am missing something. Can someone help me out?

  • Damiaan 442 posts 1302 karma points MVP 6x c-trib
    Nov 12, 2015 @ 00:40
    Damiaan
    103

    Found it!

    public MyUrlProvider()
      : base(UmbracoConfig.For.UmbracoSettings().RequestHandler)
    { }
    

    when inheriting from the DefaultUrlProvider

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Nov 20, 2015 @ 06:59
    Simon Dingley
    0

    Had the same problem - thanks for sharing!

  • Carl Jackson 139 posts 478 karma points
    Nov 26, 2015 @ 10:43
    Carl Jackson
    0

    Just having a similar issue.

    Can someone explain if Damiaan has the correct fix?

    All this is doing is implementing the backward compatibility fix from the core. Which is basically exactly the same as calling the deprocated constructor.

    Is there a preferred way to initiate the constructor. I imagine the core code does this with a resolver UrlProviderResolver which is why using UmbracoConfig is now deprecated?

    Basically my question is : Is there a nice way to use UrlProviderResolver and register a custom class which extends DefaultUrlProvider without hard coding the config?

    Thanks

  • Stephen 767 posts 2273 karma points c-trib
    Nov 26, 2015 @ 12:39
    Stephen
    1

    What Damian says.

    Core "resolves" the IUrlProvider instances ie it calls their parameter-less constructors. So the parameter-less ctor is still used by Core. However, we have an ultimate goal (v8) of moving to proper dependency injections. The new ctor would be used and the config section would be provided by the injection container.

    At the moment we are in-between: the new ctor is here, the old one is obsolete, but you still have to use it. Sorry for the confusion ;-)

  • Carl Jackson 139 posts 478 karma points
    Nov 26, 2015 @ 12:55
    Carl Jackson
    0

    Thanks for clearing up Stephen.

    Surely the parameter less constructor shouldn't be marked as obsolete as yet though?

    Adding a workaround by duplicating core code means future nuget upgrades will not mark my code with an obsolete warning as I have just implemented the none obsolete constructor in an obsolete way!

    I understand adding in code ready for the IOC in V8 but think old methods should be marked obsolete when v8 is released and not now.

    Thanks

    Carl

  • organic 108 posts 157 karma points
    May 03, 2016 @ 16:32
    organic
    0

    Stephen, when you say "you still have to use it", is 'it' the old or new constructor?

    I have code:

        public class UrlsWithTagsProvider : IUrlProvider
    {
        readonly IUrlProvider _provider = new DefaultUrlProvider();
    .
    .
    .
    }
    

    Is it OK, or do I need to change it to:

    readonly IUrlProvider _provider = new DefaultUrlProvider(UmbracoConfig.For.UmbracoSettings().RequestHandler);
    
  • Sotiris Filippidis 286 posts 1501 karma points
    May 09, 2016 @ 09:17
    Sotiris Filippidis
    0

    I've used the new constructor (as defined by Damiaan) and it looks like GetUrl() is never called, so I think Stephen means we still have to use the old one despite the warning (please correct me if I'm wrong)

Please Sign in or register to post replies

Write your reply to:

Draft