我正在尝试注册一个具有不同配置的接口,如下所示:
private static ContainerBuilder RegisterAzureStorage(this ContainerBuilder containerBuilder, IAzureStorageOptions azureStorageOptions)
{
containerBuilder.Register(c =>
new AzureStorageKeyValuePersistenceService(
new AzureStorageKeyValuePersistenceConfig(
azureStorageOptions.DctAzureBlobConnectionString,
azureStorageOptions.DctAzureBlobContainerName)))
.As<IStreamableKeyValuePersistenceService>()
.Keyed<IStreamableKeyValuePersistenceService>(PersistenceStorageKeys.DctAzureStorage)
.SingleInstance();
containerBuilder.Register(c =>
new AzureStorageKeyValuePersistenceService(
new AzureStorageKeyValuePersistenceConfig(
azureStorageOptions.NcsAzureBlobConnectionString,
azureStorageOptions.NcsAzureBlobContainerName)))
.As<IStreamableKeyValuePersistenceService>()
.Keyed<IStreamableKeyValuePersistenceService>(PersistenceStorageKeys.NcsAzureStorage)
.SingleInstance();
return containerBuilder;
}
然后在我的构造函数中:
public ReportingController(
[KeyFilter(PersistenceStorageKeys.DctAzureStorage)] IStreamableKeyValuePersistenceService dctStorage,
[KeyFilter(PersistenceStorageKeys.NcsAzureStorage)] IStreamableKeyValuePersistenceService ncsStorage)
{
_dctStorage = dctStorage;
_ncsStorage = ncsStorage;
}
和用法:
await _dctStorage.SaveAsync(........);
await _ncsStorage.SaveAsync(........);
但是,在执行时,它只会拾取最后一次注册并将两个对象保存到同一位置。
我可以使用可枚举方法让它工作:
public ReportingController(IEnumerable<IStreamableKeyValuePersistenceService> storage)
{
_storage = storage;
}
然后对于可枚举的每个,但如果可能的话我更愿意使用键控方法。
关于我所缺少的任何想法?
慕哥9229398
相关分类