public static IServiceCollection AddAzureEventBus(this IServiceCollection services) { var serviceProvider = services.BuildServiceProvider(); var configuration = serviceProvider.GetRequiredService <IConfiguration>(); const string connStrEnvVarName = "ESZOP_AZURE_EVENTBUS_CONN_STR"; const string topicNameVarName = "ESZOP_AZURE_EVENTBUS_TOPIC_NAME"; const string subNameVarName = "ESZOP_AZURE_EVENTBUS_SUB_NAME"; var connStr = EnvironmentHelpers.GetRequiredEnvVariable(connStrEnvVarName); var topicName = configuration.GetRequiredConfigValue(topicNameVarName, "EventBus:AzureEventBus:TopicName"); var subName = configuration.GetRequiredConfigValue(subNameVarName, "EventBus:AzureEventBus:SubscriptionName"); services.Configure <AzureEventBusConfig>(config => { config.ConnectionString = connStr; config.TopicName = topicName; config.SubscriptionName = subName; }); services.AddSingleton <IEventBus, AzureEventBus>(); return(services); }