我正在尝试注册一个具有不同配置的接口,如下所示: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; }然后对于可枚举的每个,但如果可能的话我更愿意使用键控方法。关于我所缺少的任何想法?
1 回答
慕哥9229398
TA贡献1877条经验 获得超6个赞
对于以后遇到这个问题的人,我错过了注册,在这种情况下,执行接口IReportingController
需要注册WithAttributeFiltering()
如下:
containerBuilder.RegisterType<ReportingController>().As<IReportingController>().WithAttributeFiltering();
- 1 回答
- 0 关注
- 89 浏览
添加回答
举报
0/150
提交
取消