我正在使用服务总线触发器构建功能应用程序v2.0。我已经实现了启动类,但是想知道一种更好的方法,该方法是在类(已注入依赖项)中的方法中解决所有依赖项后在启动时运行的方法。
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
}
}