1

我正在构建一个带有服务总线触发器的函数应用程序 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
    }
}
4

0 回答 0