我有一个 WPF 应用程序,它使用Prism.Wpf
和Prism.Unity
NuGet 包(两者6.3.0
)。我目前正在引导程序类(见下文)中手动在 Unity 容器中注册类型,并且一切正常。
internal class Bootstrapper : UnityBootstrapper
{
protected override DependencyObject CreateShell()
{
return Container.Resolve<MainWindow>();
}
protected override void InitializeShell()
{
Application.Current.MainWindow.Show();
}
protected override void ConfigureContainer()
{
base.ConfigureContainer();
// Register types
Container.RegisterType<IDialogService, DialogService>(new ContainerControlledLifetimeManager());
}
}
但是,当我尝试按约定Microsoft.Practices.Unity.DuplicateTypeMappingException
注册类型时,在 Unity 容器中注册类型时会得到一个。
按约定注册的代码:
protected override void ConfigureContainer()
{
base.ConfigureContainer();
// Register types by convention
Container.RegisterTypes(
AllClasses.FromLoadedAssemblies(),
WithMappings.FromMatchingInterface,
WithName.Default,
WithLifetime.ContainerControlled);
}
异常消息:
An attempt to override an existing mapping was detected for type Prism.Regions.IRegionNavigationContentLoader with name "", currently mapped to type Prism.Unity.Regions.UnityRegionNavigationContentLoader, to type Prism.Regions.RegionNavigationContentLoader.
使用 Prism & Unity 时如何按约定注册类型?