I am building a function app v2.0 with service bus trigger. I have the startup class implemented, but want to know the better way of calling a method which is in a class (with dependencies injected) that should run in startup after all the dependencies are resolved.
public class Startup : FunctionsStartup {
public override void Configure(IFunctionsHostBuilder builder) {
builder.Services.AddHttpClient();
builder.Services.AddAutoMapper(typeof(Startup));
//Need to call Ensurer.EnsureSomething here
}
}
public class Ensurer {
private ILogger _logger;
private IHttpClientFactory _clientFactory;
public Ensurer(ILogger logger, IHttpClientFactory httpClientFactory) {
_logger = logger;
_clientFactory = _clientFactory;
}
public void EnsureSomething() {
var httpClient = _clientFactory.CreateClient();
//call rest api to ensure prerequisite
}
}