问题标签 [prism-7]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
79 浏览

mvvm - Xamarin.Forms 的棱镜

我已经在 Xamarin.Forms 中使用 Prism MVVM 几个星期了,并且还浏览了它的文档。我知道我可能只是触及了表面。但是,是否可以肯定地说它提供的本质上是一种不同的导航方法(可能还有依赖注入)?我想念更多的东西,如果有人能启发我,我会很感激。

0 投票
0 回答
170 浏览

wpf - Prism-7 稳定了吗?

有没有人成功使用过当前的 Prism 7(Prism.Core、Prism.Unity 和 Prism.Wpf——所有版本均为 7.1.0.431)或后续的 7.2.0 预发布版本?

我遇到了 7.1.0.431 的问题。Prism.Unity 包对 Unity.Abstractions 4.1.3 有明确的依赖关系,但 Unity.Abstractions 3.3.1 也有一个未说明的依赖关系。这是一个已知问题吗?是否有解决方法?

为 Prism7 使用最新的 Nuget 包(Prism.Core、Prism.Unity 和 Prism.Wpf——所有版本均为 7.1.0.431)我遇到了与 Unity.Abstractions 的依赖冲突,该冲突在任何地方都没有说明,可能是由于在那个包裹。我可能错过了一些东西,但我不这么认为。

那是一个死胡同,所以我备份了几个版本,认为我可以找到一个稳定运行的版本,但遇到了另一个问题,即完全限定类型名引用 System.RunTime.CompilerServices.Unsafe(可作为 Nuget 包的可移植类库) . 我看到这个问题有很多命中,绑定重定向似乎不起作用。其他人评论说问题不在于 Nuget,而在于用于分发软件的包装,我应该直接向 Prism 团队询问。

我浏览了可用信息和一些代码,发现包装器(适配器设计模式)现在正在用于容器访问,并且有一个新的预发布版本可用。

我正处于一个十字路口,我需要使用旧版软件(Prism 5|6),或者可能使用预发布版本(它是一个内部的,不是面向客户的应用程序)来粗略处理它,但我想感受一下无需花费大量时间即可获得稳定性。我愿意追求这一点,以避免完成我正在开发的应用程序然后升级。

我正在编码,但这个问题不在于代码本身。我可以补充一点,7.1.0.431 之前的早期版本的问题在从我的应用程序调用 UnityBootstrapper 的 Run 方法并获取回调到无偿(简单调用基本方法)InitializeModules 方法时出现异常,这是预期返回之前的最后一个方法来自 UnityBootstrapper Run 方法的 App 调用。我意识到引导程序已被弃用,它的功能是嵌入到 PrismApplication 中,但它显然仍然存在。相对于较早的版本,我更喜欢迁移到最新最好的版本。

其次是异常:

如果我能获得关于使用哪个版本的一些指导并确保其他人已成功使用它,我很乐意提供更多代码或回答任何问题,甚至构建和调试它。非常感谢您对 Prism 就绪性和稳定性的任何评论,确认这些是已知问题或是否有解决方法。

0 投票
1 回答
775 浏览

c# - Register singletons as collection of Interfaces with Prism 7

I am converting a Prim 6 using MEF for IOC to Prism 7 Unity since MEF is not longer supported. The biggest difference I have to contend with is the presumption in MEF that everything is singleton by default while Unity tends to assume the opposite.

I have most of it converted but one thing I ran into was having a constructor reference a singleton via collections. For example, I have these interfaces and classes:

with DebugService and OtherService registers as singletons and mapped to both of their respective interfaces:

The intent is DebugService/IDebugService and OtherService/IOtherService are registered/mapped as singletons which would return the same instance but IAppService as named instances of each so there can be more one IAppService registered. Any call to get a collection would include the singleton of DebugService and OtherService.

The second part is what is giving me a problem. Getting a collection of IAppService in a constructor always generates new instances. So, if I have this:

What will happen is the constructor for DebugService will be hit twice. Once for the IDebugService injection for BOTH constructors and again specifically for the IEnumerable. If I comment out , IEnumerable<IAppService> services then it is only hit once. How can I have one and only one instance of the services but still register them with other interfaces to obtain as collections.


UPDATE

Thanks to Haukinger's response, I took a look at Prism's github since that overload is not exposed by the module. Turns out they are adding it in 7.2. THe latest preview (5 days old as of the time of this writing) has it merged in:

https://github.com/PrismLibrary/Prism/pull/1668


UPDATE 2

Unfortunately, it still seems to be a problem. I changed the registration to this and it still is hit twice:

Upgrading PRISM to the preview will not make a difference since it still references the same unity versions. But updating the unity packages will break Prism since they contain braking changes (looks like in Unity.Abstraction).


ANSWER THANKS TO HAUKINGER

Haukinger put me on the right track so give him a bump if this helps!!

Since prism 7 (currently) is using Unit Container 5.8 / Unity Abstraction 3, we have to use the InjectionFactory which is marked as obsolete and will soon be removed. To get the above to work, I had to do this (soooo gross):

0 投票
2 回答
392 浏览

wpf - Prism/WPF 中的新外壳/窗口显示错误视图

这个答案的启发,我创建了一个通用的 Shell(Prism,WPF),如下所示:

初始外壳创建于App.CreateShell()

这工作正常,正确的视图显示在初始外壳中。

然后我尝试创建第二个 Shell,StartScreenViewModel从中显示不同的视图:

这将打开一个新窗口,但它显示的视图与第一个窗口 ( StartScreen) 相同,而不是MainScreen。我在这里做错了什么?

0 投票
2 回答
1621 浏览

c# - 主窗口之前的 WPF PRISM 7 登录窗口

我是 WPF/Prism 的新手,我正在尝试执行以下操作:我需要在启动主窗口之前加载登录视图(窗口或用户控件)。成功登录后,删除登录视图并转到 Main Mindow。

我在这里查看了几个答案,但所有答案都在使用 boostrapper 类引用旧版本的 PRISM。

我有一个 WPF (Prism 7) 应用程序,其中包含主项目和一个授权模块。

从我的主项目 App.xaml.cs

在授权模块中,我有我的 LoginView / LoginViewModel。授权模块注册一个 LoginService 将被注入到 LoginViewModel

LoginViewModel 将负责使用此 LoginService 对用户进行身份验证。

我看到的部分答案显示如下:

但是,这似乎有点不必手动实例化 LoginView 而不是让容器为您做这件事。

此外,PRISM 7 上的 InitiallizeShell 期望创建当前的 shell。我不确定是否应该使用传递给激活主窗口的这个值。

我还在 Github 上阅读了 Brian Lagunas 本人的文章,可能会使用 EventAggregator(我已经尝试过)。我已经让授权模块注册了 EventAggregator 并从 LoginViewModel 成功登录后,发布了 SuccessLoginEvent 但我可以弄清楚如何从主应用程序订阅该事件

所以基本上预期的结果是,当应用程序启动时,如果用户未登录,则显示 LoginView,在用户对其进行身份验证后,将他带到已加载所有需要的模块的 MainWindow。

任何帮助将不胜感激。

0 投票
0 回答
187 浏览

xamarin.forms - 为什么 Prism navigationService.NavigateAsync 不在 INavigationResult 中返回异常?

突然之间,我的基于 Prism 7.1 的 Xamarin Forms 应用程序 (4.1) 没有处理任何 INavigationAware 方法中的异常。过去发生的情况是,如果目标页面的视图模型中发生了不愉快的事情,从 NavigateAsync 方法返回的 INavigationResult 将其“成功”属性设置为 false,我可以通过检查“异常”属性做出相应的反应。

现在,突然之间,目标视图/视图模型 INavigationAware 实现中的异常未处理并导致我的应用程序崩溃。我创建了一个小型测试项目,并且安装了相同的 Prism 和 XF 包,它可以按预期工作。我现在对此完全感到困惑。

到底会发生什么?我已经清理了所有项目,删除了 obj 和 bin 文件夹,多次重启了 VS,重启了设备,我能想到的一切。

0 投票
1 回答
523 浏览

c# - PRISM navigationService 在 ViewModel 构造函数中为空

情况:我有这些物品:

MainMenuPage包含,MainMenuView如下所示:

MainMenuView 自动连接到 MainMenuViewModel,如下所示:

这是我的 MainMenuViewModel 构造函数:

问题:问题是 MainMenuViewModel 的构造函数中的 navigationService 为空。构造函数确实被调用,所以我认为这不是自动布线的问题。构造函数被 PRISM 框架的自动连接函数调用。

有人知道为什么 navigationService 为空吗?

提前致谢!

编辑:

解决方案:我部分使用了 Roubachof 的解决方案。

我创建了一个 MainMenuPageViewModel。我摆脱了 MainMenuViewModel,因为不再需要了。我将 ICommands(在评论中提到)移到了新的 MainMenuPageViewModel。

很明显,在阅读 PRISM 时,我对页面和视图感到困惑。我以为视图有视图模型,但实际上页面有视图模型。这是因为 MVVM 和 Xamarin.Forms 使用不同的术语。既然我知道了这一点,我将去对我的应用程序的结构进行一些更改。

0 投票
1 回答
2630 浏览

mvvm - Prism 7 抛出 ResolutionFailedException:没有可用于类型的公共构造函数(接口)

我正在使用 Prism 7.2 开发 WPF 应用程序。我有一个模块,它实现了IModule接口,我在RegisterTypes方法中注册了视图和视图模型,例如:

当我尝试解决实现时出现问题:

因此我得到以下Unity.ResolutionFailedException:“解决失败并出现错误:没有公共构造函数可用于类型 XXX.Infrastructure.Interfaces.IView。”

该类PanelOptimizationViewModel派生自一个基类:

ViewModelBase看起来像这样:

接口IViewIViewModel定义在一个通用的基础设施项目中。它们没有在容器中的任何地方注册,但是如果我删除IPanelOptimizationInputViewModel参数,则不会引发运行时异常 - 导致我认为我也不需要这样做。

据我所知,Unity.Container将使用“最参数化”的构造函数(请参阅Unity not using the default constructor of the class),但我无法在 Register 方法中提供参数来指定这一点,因为显然可以之前(Prism 7 之前的容器抽象),使用 RegisterType 方法。

如何解决这个问题?是否存在允许我为构造函数注入设置注册的 Prism.Ioc.IContainerRegistry.Register 方法的重载?

我应该直接使用 Unity 容器吗?

基本上,我正在尝试将子视图的视图模型注入我的“主”视图模型的构造函数中,但只要在基类上调用错误的构造函数并使用错误的参数集,这并不顺利......(如果这是正在发生的事情)。

不用说,所有的子视图和视图模型都已经在模块的 RegisterTypes 方法中注册了。

对此的任何帮助将不胜感激

0 投票
2 回答
1520 浏览

c# - 如何在使用 Prism 7.2 的视图之间导航?

我正在编写一个应用程序,我想在其中放置导航。此应用程序使用 WPF,我使用的是 Prism 7.2.0.1367。

所以我创建了 2 个视图:一个HomePage和一个ModeFileAttente视图。

我也在使用 MVVM 模式。

这是我的app.xaml.cs

我的HomePage.xaml

这是视图模型:

我也有一Bootstrapper堂课:

我的 MVVM 模式运行良好,但是当我想在“主页”和“ModeFileAttente”视图之间导航时,除了视图上的“System.Object”之外什么也没有发生。

我已经搜索了可能是什么问题,但我没有解决我的问题。

这个版本的棱镜还有人遇到这个错误吗?

PS:我的 2 视图位于“视图”文件夹中,与 ViewModel 文件夹中的视图模型相同

0 投票
1 回答
176 浏览

.net-core - prism 7.2中的模态对话框

我正在开发一个 .net core 3 wpf Prism 应用程序,我想知道如何使用 Prism 7.2 中的新 IDIAlogAware 界面使主窗口在模式对话框显示时变灰。我正在寻找类似 Prism xamarin.forms 中的属性 DialogLayout.MaskStyle 的东西?