/// <summary>
        /// <para>初始化与领域对象相关的行为,由于许多行为是第一次使用对象的时候才触发,这样会导致没有使用对象却需要一些额外特性的时候缺少数据</para>
        /// <para>所以我们需要在使用领域驱动的之前执行初始化操作</para>
        /// </summary>
        internal static void Initialize()
        {
            if (_initialized)
            {
                return;
            }
            _initialized = true;

            //以下代码执行顺序不能变
            TypeIndex = GetTypeIndex();

            //指定动态类型的定义
            RemoteType.Initialize();

            //执行远程能力特性的初始化,收集相关数据
            RemotableAttribute.Initialize();


            //触发没有派生类的领域对象的静态构造
            foreach (var objectType in TypeIndex)
            {
                if (DerivedClassAttribute.IsDerived(objectType))
                {
                    continue;                                              //不执行派生类的
                }
                DomainObject.StaticConstructor(objectType);
            }

            //先执行派生类的
            DerivedClassAttribute.Initialize();

            //再执行扩展的
            ExtendedClassAttribute.Initialize();
        }
Esempio n. 2
0
        public static void NotifyDeleted(RemoteType remoteType, object id)
        {
            var arg       = CreateEventArg(remoteType, id);
            var eventName = RemoteObjectDeleted.GetEventName(remoteType);

            EventPortal.Publish(eventName, arg);
        }
Esempio n. 3
0
        private static DTObject CreateEventArg(RemoteType remoteType, object id)
        {
            var arg = DTObject.CreateReusable();

            arg["identity"] = AppContext.Identity;
            arg["typeName"] = remoteType.FullName;
            arg["id"]       = id;
            return(arg);
        }
Esempio n. 4
0
        private static void SubscribeEvents()
        {
            var remoteTypes = RemoteType.GetTypes();

            foreach (var remoteType in remoteTypes)
            {
                RemoteObjectUpdated.Subscribe(remoteType);
                RemoteObjectDeleted.Subscribe(remoteType);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 取消订阅
        /// </summary>
        private static void CancelEvents()
        {
            var remoteTypes = RemoteType.GetTypes();

            foreach (var remoteType in remoteTypes)
            {
                //取消订阅对象被修改和删除的事件
                RemoteObjectUpdated.Cancel(remoteType);
                RemoteObjectDeleted.Cancel(remoteType);
            }
        }
        protected void UseDefines(DTObject arg, Action <AggregateRootDefine, object> action)
        {
            var typeName = arg.GetValue <string>("typeName");
            var defines  = RemoteType.GetDefines(typeName);

            foreach (var define in defines)
            {
                var idProperty = DomainProperty.GetProperty(define.MetadataType, EntityObject.IdPropertyName);
                var id         = DataUtil.ToValue(arg.GetValue(EntityObject.IdPropertyName), idProperty.PropertyType);
                action((AggregateRootDefine)define, id);
            }
        }
Esempio n. 7
0
 private TypeDefine(string typeName, string metadataCode, TypeMetadata metadata, Type domainInterfaceType, Type objectType, string qualifiedName)
 {
     this.TypeName            = typeName.FirstToUpper();
     this.MetadataCode        = metadataCode;
     this.Metadata            = metadata;
     this.DomainInterfaceType = domainInterfaceType;
     this.ObjectType          = objectType;
     this.Constructor         = this.ObjectType.ResolveConstructor(typeof(TypeDefine), typeof(bool));
     this.QualifiedName       = qualifiedName;
     InitMetadataType();
     AddDefineIndex(typeName, this);                            //加入索引
     this.RemoteType = GetRemoteType();
     RemoteType.AddDefineIndex(this.RemoteType.FullName, this); //加入索引
 }
Esempio n. 8
0
 private TypeDefine(string typeName, string metadataCode, TypeMetadata metadata, Type domainInterfaceType, Type objectType, string qualifiedName)
 {
     this.TypeName            = typeName.FirstToUpper();
     this.MetadataCode        = metadataCode;
     this.MetadataSchemaCode  = DTObject.Create(metadataCode).GetSchemaCode(false, false);
     this.Metadata            = metadata;
     this.DomainInterfaceType = domainInterfaceType;
     this.ObjectType          = objectType;
     this.Constructor         = this.ObjectType.ResolveConstructor(typeof(TypeDefine), typeof(bool));
     this.QualifiedName       = qualifiedName;
     InitMetadataType();
     this.RemoteType = GetRemoteType();
     if (!IsIgnore(typeName, this))
     {
         AddDefineIndex(typeName, this);                            //加入索引
         RemoteType.AddDefineIndex(this.RemoteType.FullName, this); //加入索引
     }
 }
Esempio n. 9
0
        public static void Cancel(RemoteType remoteType)
        {
            var eventName = GetEventName(remoteType);

            EventPortal.Cancel(eventName);
        }
Esempio n. 10
0
        public static void Subscribe(RemoteType remoteType)
        {
            var eventName = GetEventName(remoteType);

            EventPortal.Subscribe(eventName, Handler);
        }
Esempio n. 11
0
 public static string GetEventName(RemoteType remoteType)
 {
     return(string.Format("{0}Updated", remoteType.FullName));
 }
Esempio n. 12
0
 /// <summary>
 /// 通知对象已删除
 /// </summary>
 /// <param name="type"></param>
 /// <param name="id"></param>
 internal static void NotifyDeleted(RemoteType type, object id)
 {
     Implement.NotifyDeleted(type, id, _config.MembershipAddresses);
 }
 /// <summary>
 /// 对象已删除
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public static string ObjectDeleted(RemoteType type)
 {
     return(_getObjectDeleted(type));
 }
 public static string GetObject(RemoteType type)
 {
     return(_getObject(type));
 }
Esempio n. 15
0
 /// <summary>
 /// 通知对象已删除
 /// </summary>
 /// <param name="type"></param>
 /// <param name="id"></param>
 internal static void NotifyDeleted(RemoteType type, object id)
 {
     RemoteService.NotifyDeleted(type, id);
 }