Copied to clipboard

Flag this post as spam?

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

  • Murray Roke 486 posts 908 karma points c-trib
    Dec 21, 2022 @ 22:41
    Murray Roke

    DI Registration WithParameter

    Hi all,
    I wish to register an object with DI where one parameter comes from the container, and the other is specified at registration time.

    I have a class for which the constructor takes 2 parameters like so:

    public PriceCache(string relativeDiskCachePath, DynamicsPriceRepository priceRepo)

    In Umbraco 7 I could register that with the DI container like so:

                   .WithParameter("relativeDiskCachePath", "~/App_Data/DynamicsCache/Prices")
                   // other constructor parameter injected automatically.

    How would I do this in Umbraco 8?

  • Murray Roke 486 posts 908 karma points c-trib
    Dec 21, 2022 @ 22:59
    Murray Roke

    I got around it by making the string constructor param a type I could register instead of a string, And registered it like so:

            composition.RegisterUnique(new PriceCacheConfiguration(){RelativeDiskCachePath = "~/App_Data/DynamicsCache/Prices" });
Please Sign in or register to post replies

Write your reply to: