Prism应用开发(八)——松耦合组件之间通信

本文深入探讨了Prism框架下组件间通信的三种方式:使用Commands实现全局共享,通过Shared Service进行模块间通信,以及利用Event Aggregator服务发布和订阅事件,以实现松耦合的设计。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、Commands

创建一个全局的command,该command将会在各个组件之间共享。

public static class GlobalCommands
{
public static CompositeCommand MyCompositeCommand = new CompositeCommand();
}

GlobalCommands.MyCompositeCommand.RegisterCommand(command1);
GlobalCommands.MyCompositeCommand.RegisterCommand(command2);

<Button Name="MyCompositeCommandButton" Command="{x:Static
local:GlobalCommands.MyCompositeCommand}">Execute My Composite Command </Button>

二、Shared Service

module之间可以通过Shared Service相互通信而不用直接引用另一个module。

protected void RegisterViewsAndServices()
{
_container.RegisterType<IMarketFeedService, MarketFeedService>(new
ContainerControlledLifetimeManager());
//...
}

三、Event Aggregation

Prism提供了为松耦合组件之间通信提供了事件的机制。这个机制基于event

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值