コード例 #1
0
ファイル: IocManager.cs プロジェクト: supermax/TMS
        /// <summary>
        /// Registers the specified implementation instance.
        /// </summary>
        /// <typeparam name="TInterface">The type of the interface.</typeparam>
        /// <typeparam name="TImplementation">The type of the implementation.</typeparam>
        /// <param name="implementationInstance">The implementation instance.</param>
        /// <param name="isWeakRef">if set to <c>true</c> [is weak ref].</param>
        public void Register <TInterface, TImplementation>(TImplementation implementationInstance, bool isWeakRef = false)
            where TImplementation : TInterface
        {
            ArgumentValidator.AssertNotDefault(implementationInstance, "implementationInstance");
            var success = ConfigureType(implementationInstance.GetType(), implementationInstance);

            if (success)
            {
                return;
            }

            Register(typeof(TInterface), typeof(TImplementation), true, null, isWeakRef, implementationInstance);
        }
コード例 #2
0
        /// <summary>
        ///     Publishes the internal.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="payload">The payload.</param>
        /// <param name="async">if set to <c>true</c> [async].</param>
        /// <returns></returns>
        internal WeakDelegatesManager PublishInternal <T>(T payload, bool async)
        {
            ArgumentValidator.AssertNotDefault(payload, "payload");
            Log(LogType.Log, "{0}.Publish(payload=\"{1}\") [START]", this, payload);

            var payloadType = typeof(T);
            var manager     = GetManager(payloadType, false);
            var tType       = payloadType;

            if (manager == null)
            {
                payloadType = payload.GetType();

                Log(LogType.Warning, "{0}.Publish<{1}>(payload=\"{2}\") [TYPE_MISSMATCH], retrying with type: {3}...",
                    this, tType, payload, payloadType);
                manager = GetManager(payloadType, false);
            }
            if (manager == null)
            {
                Log(LogType.Warning, "{0}.Publish<{1}>(payload=\"{2}\") [TYPE_MISSMATCH], can't get manager by type: {3}. Publish aborted.",
                    this, tType, payload, payloadType);
                return(null);
            }

            Log(LogType.Log, "{0}.Publish(payload=\"{1}\") [MANAGER=\"{2}\"]", this, payload, manager);

            Action act = () =>
            {
                manager.Raise(async, payload);
                HandleBroadcastPayload(payload as IBroadcastPayload);
            };

            if (ThreadHelper.Default.IsMainThread())
            {
                act();
            }
            else
            {
                ThreadHelper.Default.CurrentDispatcher.Dispatch(act);
            }

            return(manager);
        }