Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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:
builder.RegisterType<DynamicsPriceRepository>(); builder.RegisterType<PriceCache>() .WithParameter("relativeDiskCachePath", "~/App_Data/DynamicsCache/Prices") // other constructor parameter injected automatically. .SingleInstance();
How would I do this in Umbraco 8?
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.Register<DynamicsPriceRepository>(Lifetime.Singleton); composition.RegisterUnique(new PriceCacheConfiguration(){RelativeDiskCachePath = "~/App_Data/DynamicsCache/Prices" }); composition.Register<PriceCache>(Lifetime.Singleton);
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
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:
In Umbraco 7 I could register that with the DI container like so:
How would I do this in Umbraco 8?
I got around it by making the string constructor param a type I could register instead of a string, And registered it like so:
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.