1
我有一些功能切換,我包括在我的.NET應用程序使用StructureMap。我想要註冊該功能以達到兩個目的。的診斷頁面上所有IFeatures
在StructureMap中有兩次註冊同一個對象的好方法嗎?
- 顯示當前狀態。
- 在依賴於給出
IFeature
實現服務的構造函數使用某些情況下
這裏是我的設置。我想知道的是,我做對了嗎?有沒有更好的辦法可以做到這一點?
class HotNewFeature : IFeature { ... }
class ServiceThatUsesFeature
{
public ServiceThatUsesFeature(HotNewFeature hotNewFeature) { ... }
}
// Type registry setup
For<HotNewFeature>().Singleton().Use<HotNewFeature>();
For<IFeature>().Singleton().Add(c => c.GetInstance<HotNewFeature>);
For<ServiceThatUsesFeature>().Singleton().Use<ServiceThatUsesFeature>());
// Get all instances on the diagnostics page:
IEnumerable<IFeature> features = ServiceLocator.Current.GetAllInstances<IFeature>();
我想到的是,診斷頁面上,features
會在這種情況下,包含IEnumerable
用一個單一的元素,的HotNewFeature
實例。
請詳細說明您希望返回GetAllInstances的實例。 –