我正在尝试在Unity中注册多个区域:
public class ModuleA : IModule
{
private IUnityContainer _container;
private IRegionManager _regionManager;
public ModuleA(IUnityContainer container, IRegionManager regionManager)
{
_container = container;
_regionManager = regionManager;
}
public void Initialize()
{
IRegion region = _regionManager.Regions[RegionNames.ToolbarRegion];
region.Add(_container.Resolve<ToolbarView>());
region.Add(_container.Resolve<ToolbarView>());
region.Add(_container.Resolve<ToolbarView>());
region.Add(_container.Resolve<ToolbarView>());
region.Add(_container.Resolve<ToolbarView>());
}
}
}
但我无法用MEF成功
[ModuleExport(typeof(ModuleAModule))]
public class ModuleAModule : IModule
{
[Import]
private IRegionManager _regionManager;
public void Initialize()
{
_regionManager.RegisterViewWithRegion(RegionNames.ContentRegion, typeof(ContentView));
IRegion region = _regionManager.Regions[RegionNames.ToolbarRegion];
}
}
我可以获得该地区,但我不知道如何将解析转化为MEF。