Skip to content

class Mediator

cangjie
public class Mediator <: IMediator

功能:提供请求分发与通知发布的默认中介者实现。

父类型:

成员概览

成员功能
init(IServiceProvider)使用服务提供器创建中介者实例。
func send(TRequest)发送请求并返回响应。
func publish(TNotification)发布通知给所有已注册处理器。

init(IServiceProvider)

cangjie
public init(services: IServiceProvider)

功能:使用服务提供器创建中介者实例。

参数:

  • services: IServiceProvider - 用于解析处理器和管道行为的服务提供器。

func send(TRequest)

cangjie
public func send<TRequest, TResponse>(request: TRequest): TResponse where TRequest <: IRequest<TResponse>

功能:发送请求并返回响应。

参数:

  • request: TRequest - 要发送的请求实例。

返回值:

  • TResponse - 请求处理器返回的响应结果。

异常:

  • NoneValueException - 当请求处理器未注册或返回结果无法转换为目标类型时抛出。

func publish(TNotification)

cangjie
public func publish<TNotification>(notification: TNotification): Unit where TNotification <: INotification

功能:发布通知给所有已注册处理器。

参数:

  • notification: TNotification - 要发布的通知实例。

返回值:

  • Unit - 无返回值。