コード例 #1
0
        /// <summary> 注册 </summary>
        /// <param name="resolver"></param>
        /// <param name="value"></param>
        /// <param name="key"></param>
        public static void Register(this IResolver resolver, object value, object key = null)
        {
            resolver.Register(value.GetType(), value, key);
            var interFaces = value.GetType().GetTypeInfo().GetInterfaces();

            foreach (var interFace in interFaces)
            {
                resolver.Register(interFace, value, key);
            }
        }
コード例 #2
0
        private static void InternalRegister(bool registration)
        {
            if (ArgillaSettings.Current.Node == null)
            {
                return;
            }

            RegisterRequest registerRequest = new RegisterRequest()
            {
                ServiceName   = ArgillaSettings.Current.Node.ServiceName,
                EndpointSync  = ArgillaSettings.Current.Node.EndpointSync,
                EndpointAsync = ArgillaSettings.Current.Node.EndpointAsync
            };

            try
            {
                RegisterResponse registerResponse = registration ? resolver.Register(registerRequest) : resolver.Unregister(registerRequest);

                if (registerResponse == null || !registerResponse.Success)
                {
                    Manage(new RegistrationException(String.Format("Cannot {1} service \"{0}\"", registerRequest.ServiceName, (registration ? "register" : "unregister"))));
                }
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    Manage(new RegistrationException(String.Format("Cannot {1} service \"{0}\"", registerRequest.ServiceName, (registration ? "register" : "unregister"))));
                }

                logger.Error(e, e.Message);
            }
        }
コード例 #3
0
ファイル: TreeBuilder.cs プロジェクト: FrodaSE/Froda.Console
        private CommandBase Resolve(Type command)
        {
            var instance = _resolver.Resolve(command);

            if (instance == null && _autoRegister)
            {
                _resolver.Register(command);
                instance = _resolver.Resolve(command);
            }

            return((CommandBase)instance);
        }
コード例 #4
0
ファイル: ProxyFactory.cs プロジェクト: ztxyzu/spear
        public object Create(Type type, object key = null)
        {
            var instance = _resolver.Resolve(type, key);

            if (instance != null)
            {
                return(instance);
            }
            instance = _proxyGenerator.CreateProxy(type, typeof(ProxyExecutor), _proxyProvider, key);
            _resolver.Register(type, instance, key);
            return(instance);
        }
コード例 #5
0
 /// <summary>
 /// Generic version of type registration
 /// </summary>
 /// <param name="resolver">Resolver.</param>
 /// <param name="factory">Factory.</param>
 /// <param name="lifetime">Lifetime.</param>
 /// <typeparam name="T">The 1st type parameter.</typeparam>
 public static void Register <T>(this IResolver resolver, Func <IResolver, T> factory, Lifetime lifetime = Lifetime.Transient)
 {
     resolver.Register(typeof(T), (r) => { return((T)factory(r)); }, lifetime);
 }
コード例 #6
0
 /// <summary>
 /// Generic version of type registration.
 /// </summary>
 /// <param name="resolver">Resolver.</param>
 /// <param name="singleton">Singleton.</param>
 /// <typeparam name="T">The 1st type parameter.</typeparam>
 public static void Register <T>(this IResolver resolver, T singleton)
 {
     resolver.Register(typeof(T), singleton);
 }
コード例 #7
0
 /// <summary>
 /// Generic version of type registration
 /// </summary>
 /// <typeparam name="T1"></typeparam>
 /// <typeparam name="T2"></typeparam>
 /// <param name="resolver"></param>
 /// <param name="lifetime"></param>
 public static void Register <T1, T2>(this IResolver resolver, Lifetime lifetime = Lifetime.Transient)
 {
     resolver.Register(typeof(T1), typeof(T2), lifetime);
 }
コード例 #8
0
 public void Register <TCommand>(IResolver resolver) where TCommand : CommandBase
 {
     resolver.Register <TCommand>();
     Register <TCommand>();
 }
コード例 #9
0
 public void Register <TInterface>(TInterface instance) where TInterface : class
 {
     _resolver.Register(instance);
 }