I need to inject dependency in Startup.cs
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddTransient<IAppService, AppService>();
//how to inject for the rest
}
}
to achieve the line below:
new AppService(new CacheRepository(new ConfigRepository()))
instead of below or others
new AppService(new ConfigRepository())
Decorator pattern with multiple implementation below:
public class ConfigRepository : IRepository
{
public async Task<IEnumerable<Data>> ReadDataAsync()
{
//...
}
}
public class CacheRepository : IRepository
{
private readonly IRepository _pository;
public CacheConfigRepository(IRepository repository)
{
_pository = repository;
}
public async Task<IEnumerable<Data>> ReadDataAsync()
{
//...
}
}
Environment: .Net Core 2.2, Azure Functions
Update
Answer:
Thanks @Timo for providing the link below https://github.com/khellang/Scrutor
How to overwrite a scoped service with a decorated implementation?