Ejemplo n.º 1
0
 /// <summary>
 /// 获取JsonWebSocketApiService实例
 /// </summary>
 /// <param name="actionContext">Api行为上下文</param>
 /// <returns></returns>
 private IJsonWebSocketApiService GetJsonWebSocketApiService(ActionContext actionContext)
 {
     try
     {
         var serviceType = actionContext.Action.DeclaringService;
         var instance    = this.DependencyResolver.GetService(serviceType);
         return(instance as IJsonWebSocketApiService);
     }
     catch (Exception ex)
     {
         var resolveException = new ResolveException(actionContext.Action.DeclaringService, ex);
         var exceptionContext = new ExceptionContext(actionContext, resolveException);
         this.SendRemoteException(exceptionContext);
         this.ExecGlobalExceptionFilters(exceptionContext);
         return(null);
     }
 }
Ejemplo n.º 2
0
        public void Exception_In_Factory_Method_Throws_ResolveException()
        {
            var target = new Container();

            target.Register <ISimpleTestService>(c => { throw new InvalidOperationException(); });

            ResolveException thrownException = null;

            try
            {
                target.Resolve <ISimpleTestService>();
            }
            catch (ResolveException ex)
            {
                thrownException = ex;
            }

            Assert.IsNotNull(thrownException);
            Assert.AreEqual(thrownException.ServiceType, typeof(ISimpleTestService));
            Assert.IsTrue(thrownException.Message.Contains(typeof(ISimpleTestService).ToString()), "Exception should contain the name of the interface that wasn't resolved.");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取JsonWebSocketApiService实例
        /// </summary>
        /// <param name="actionContext">Api行为上下文</param>
        /// <returns></returns>
        private IJsonWebSocketApiService GetFastApiService(ActionContext actionContext)
        {
            IJsonWebSocketApiService fastApiService = null;
            Exception innerException = null;

            try
            {
                fastApiService = (IJsonWebSocketApiService)this.DependencyResolver.GetService(actionContext.Action.DeclaringService);
            }
            catch (Exception ex)
            {
                innerException = ex;
            }

            if (fastApiService == null)
            {
                var exception        = new ResolveException(actionContext.Action.DeclaringService, innerException);
                var exceptionContext = new ExceptionContext(actionContext, exception);

                Common.SetRemoteException(this.JsonSerializer, exceptionContext);
                this.ExecGlobalExceptionFilters(exceptionContext);
            }
            return(fastApiService);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取FastApiService实例
        /// </summary>
        /// <param name="actionContext">Api行为上下文</param>
        /// <returns></returns>
        private IFastApiService GetFastApiService(ActionContext actionContext)
        {
            try
            {
                var serviceType = actionContext.Action.DeclaringService;
                var instance = this.DependencyResolver.GetService(serviceType);
                return instance as IFastApiService;
            }
            catch (Exception ex)
            {
                var exception = new ResolveException(actionContext.Action.DeclaringService, ex);
                var exceptionContext = new ExceptionContext(actionContext, exception);

                Common.SendRemoteException(actionContext.Session.UnWrap(), exceptionContext);
                this.ExecGlobalExceptionFilters(exceptionContext);
                return null;
            }
        }
 /// <summary>
 /// 获取JsonWebSocketApiService实例
 /// </summary>
 /// <param name="actionContext">Api行为上下文</param>
 /// <returns></returns>
 private IJsonWebSocketApiService GetJsonWebSocketApiService(ActionContext actionContext)
 {
     try
     {
         var serviceType = actionContext.Action.DeclaringService;
         var instance = this.DependencyResolver.GetService(serviceType);
         return instance as IJsonWebSocketApiService;
     }
     catch (Exception ex)
     {
         var resolveException = new ResolveException(actionContext.Action.DeclaringService, ex);
         var exceptionContext = new ExceptionContext(actionContext, resolveException);
         this.SendRemoteException(exceptionContext);
         this.ExecGlobalExceptionFilters(exceptionContext);
         return null;
     }
 }