Copied to clipboard

Flag this post as spam?

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


  • Nathan Woulfe 447 posts 1664 karma points MVP 5x hq c-trib
    May 18, 2021 @ 01:46
    Nathan Woulfe
    0

    Registering an open generic implementation type

    Started looking at porting packages and have hit an issue in my composer - this doesn't work anymore (worked fine in 8):

    public void Compose(IUmbracoBuilder builder)
    {
        builder.Services.AddUnique(typeof(IWorkflowRepository<>), typeof(BaseWorkflowRepository<>));
    }
    

    Throws an exception re Open generic service type x requires registering an open generic implementation type

    Advice much appreciated...

  • Nathan Woulfe 447 posts 1664 karma points MVP 5x hq c-trib
    May 18, 2021 @ 02:23
    Nathan Woulfe
    0

    My bad - should be using AddScoped, not AddUnique.

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    May 18, 2021 @ 06:18
    Andy Butland
    0

    I suspect you may have run into a limitation of the built-in Microsoft DI container available in .NET 5 that's used by Umbraco V9, as opposed to LightInject that was available in V8.

    The container is swappable for another one that provides additional features in .NET 5, but I don't suppose that's really appropriate for a package - as someone using it in a custom solution may not want that (or may want a different one).

    There's some discussion here that might offer options to resolve this.

    Andy

  • Nathan Woulfe 447 posts 1664 karma points MVP 5x hq c-trib
    May 18, 2021 @ 08:54
    Nathan Woulfe
    0

    Thanks Andy, seems to be working if I register the generic services using builder.Services.AddSingleton(), and builder.Services.AddUnique() for the services implementing the generic type. So far so good...

Please Sign in or register to post replies

Write your reply to:

Draft