Пример #1
0
        IOperationAsync CreateOperationCore(IMethod method)
        {
            var output = method.OutputMembers.Single();

            if (IsTask(output))
            {
                return new AsyncMethod(method, _binderLocator)
                       {
                           Resolver = _resolver
                       }
            }
            ;
            if (IsTaskOfT(output))
            {
                return((IOperationAsync)Activator.CreateInstance(
                           typeof(AsyncMethod <>)
                           .MakeGenericType(output.StaticType.GenericTypeArguments),
                           method, _binderLocator, _resolver));
            }
            var syncMethod = new SyncMethod(method, _binderLocator)
            {
                Resolver = _resolver
            };

            return(syncMethod.Intercept(_syncInterceptorProvider).AsAsync());
        }
        static SyncOperationDescriptor CreateSyncDescriptor(
            IType targetType,
            IMethod method,
            Func <IOperation, IEnumerable <IOperationInterceptor> > syncInterceptorProvider,
            IObjectBinderLocator binderLocator,
            IDependencyResolver resolver,
            Func <IEnumerable <IOperationInterceptorAsync> > systemInterceptors)
        {
            var attribCache = new Dictionary <Type, object[]>(3)
            {
                [typeof(IOperationInterceptor)]         = WarmUpAttribCache <IOperationInterceptor>(method.Owner, method),
                [typeof(IOperationInterceptorProvider)] =
                    WarmUpAttribCache <IOperationInterceptorProvider>(method.Owner, method),
                [typeof(HttpOperationAttribute)] = WarmUpAttribCache <HttpOperationAttribute>(method)
            };

            IOperationAsync factory()
            {
                var syncMethod = new SyncMethod(targetType, method, binderLocator, resolver, attribCache);

                return(syncMethod.Intercept(syncInterceptorProvider).AsAsync().Intercept(systemInterceptors()));
            }

            return(new SyncOperationDescriptor(method, factory));
        }
 static SyncOperationDescriptor CreateSyncDescriptor(IMethod method,
                                                     Func <IOperation, IEnumerable <IOperationInterceptor> > syncInterceptorProvider,
                                                     IObjectBinderLocator binderLocator,
                                                     IDependencyResolver resolver,
                                                     IEnumerable <IOperationInterceptorAsync> systemInterceptors)
 {
     return(new SyncOperationDescriptor(method, () =>
     {
         var syncMethod = new SyncMethod(method, binderLocator, resolver);
         return syncMethod.Intercept(syncInterceptorProvider).AsAsync().Intercept(systemInterceptors);
     }));
 }