/****************************************************************
** 文件名: EventBus.cs
** 主要类: EventBus类
** Copyright (c) 章为忠
** 创建人:
** 日 期: 2017.3.10
** 修改人:
** 日 期:
** 修改内容:
** 描 述:
** 版 本:
** 备 注:
****************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
namespace Weiz.EventBus.Core
{
public class EventBus
{
///
/// 事件总线对象
///
private static EventBus _eventBus = null;
///
/// 领域模型事件句柄字典,用于存储领域模型的句柄
///
private static Dictionary> _dicEventHandler = new Dictionary>();
///
/// 附加领域模型处理句柄时,锁住
///
private readonly object _syncObject = new object();
///
/// 单例事件总线
///
public static EventBus Instance
{
get
{
return _eventBus ?? (_eventBus = new EventBus());
}
}
///
/// 通过XML文件初始化事件总线,订阅信自在XML里配置
///
///
public static EventBus InstanceForXml()
{
if (_eventBus == null)
{
XElement root = XElement.Load(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EventBus.xml"));
foreach (var evt in root.Elements("Event"))
{
List