包更新后的 WPF 模块化初始化

WPF Modular Initialization after Package Update

嗨希望你们能帮助我。 我继承了一个项目并需要更新包,并且初始化发生了变化。

 public abstract class ModuleBase : Prism.Modularity.IModule
{
    public IUnityContainer UnityContainer { get; private set; }
    public IRegionManager RegionManager { get; private set; }

    public ModuleBase(IUnityContainer unityContainer, IRegionManager regionManager)
    {
        if (unityContainer == null)
        {
            throw new ArgumentNullException("unityContainer");
        }
        UnityContainer = unityContainer;

        if (regionManager == null)
        {
            throw new ArgumentNullException("regionManager");
        }
        RegionManager = regionManager;
    }

    public virtual void Initialize() { }//old

    public abstract void RegisterTypes(IContainerRegistry containerRegistry);//new
    public abstract void OnInitialized(IContainerProvider containerProvider);//new
}

我有这个基础,从那里扩展了不同的模块。

    public class UserModule : ModuleBase
{

    public UserModule(IUnityContainer unityContainer, IRegionManager regionManager)
        : base(unityContainer, regionManager)
    {

    }

    public override void Initialize()//old
    {
        UnityContainer.RegisterType<UserView>();
        UnityContainer.RegisterType<UserKernelSettingsView>();
        UnityContainer.RegisterType<UserNavigationItemView>();

        UnityContainer.RegisterTypeForNavigation<UserView>();
        UnityContainer.RegisterTypeForNavigation<UserKernelSettingsView>();

        RegionManager.RegisterViewWithRegion(RegionNames.NavigationRegion, typeof(UserNavigationItemView));
    }

    public override void OnInitialized(IContainerProvider containerProvider)//new
    {

    }

    public override void RegisterTypes(IContainerRegistry containerRegistry)//new
    {


    }
}

但现在我无法正确注册视图。

BR 最大值

试试这个:

public void OnInitialized(IContainerProvider containerProvider)
{
    var regionManager = containerProvider.Resolve<IRegionManager>();
    regionManager.RegisterViewWithRegion(RegionNames.NavigationRegion, typeof(UserNavigationItemView));
}

public void RegisterTypes(IContainerRegistry containerRegistry)
{
    containerRegistry.Register<UserView>();
    containerRegistry.Register<UserKernelSettingsView>();
    containerRegistry.Register<UserNavigationItemView>();

    containerRegistry.RegisterForNavigation<UserView>();
    containerRegistry.RegisterForNavigation<UserKernelSettingsView>();
}