I may be barking up the wrong tree here, but, i have the following:
var host = new HostBuilder()
.ConfigureServices(services =>
{
services.AddSingleton<IHttpClientFactory>();
services.AddScoped<IPaintMapper, PaintMapper(XXXXX, config)>();
};
I want to pass the IHttpClientFactory into my Scoped "PaintMapper", which i will provide also a config for.
How would i do this? As the IHttpClientFactory and the "config" are both required to setup the scoped instance.
I’ve been at this refactor for a while and think my brain is not handling it particularly well, so my apologies if i’m missing something normal – but i don’t see this done elsewhere, so i’m probably missing something.
>Solution :
You can do like this
services.AddScoped<IPaintMapper, PaintMapper>(provider => {
var config = provider.GetRequiredService<Config>();
var httpFactory = provider.GetRequiredService<IHttpClientFactory>();
// Do stuff with mapper
return mapper;
});