/// <summary> /// Sends the batch request to the server and clears the cache and the batchId. /// </summary> /// <param name="context">The context that sends the request.</param> /// <param name="cache">The cache containing the parameters of cached methods.</param> /// <param name="batchId">The batchId to retrieve the cached parameters.</param> /// <returns>A Task.</returns> internal static async Task ExecuteBatch(IContext context, ParametersCache cache, ThreadLocal <Guid> batchId) { if (!BatchHelper.IsInBatchMode(batchId)) { throw new InvalidOperationException("The calling thread was trying to do batch operation but it didn't begin the batch operations before."); } Guid localBatchId = batchId.Value; // Clears the batchId before executing the batch operation since after do "await" the original // thread will be used to do ExecuteBatchAsync and a new thread will be created to do the rest work. // So we will not be able to clear the original thread any more. batchId.Value = Guid.Empty; List <ParametersGroup> requests = cache.GetParameters(localBatchId); List <TaskCompletionSource <object> > tasks = cache.GetTasks(localBatchId); try { await context.ExecuteBatchAsync(requests, tasks); } catch { throw; } finally { // Clear the cache for this thread. cache.Clear(localBatchId); } }
public static bool TryGetInjectableConstructorParameters([NotNull] Type type, out IReadOnlyList <ParameterInfo> parameters) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (ParametersCache.TryGetValue(type, out parameters)) { return(parameters != null); } if (TryGetInjectableConstructorParametersInternal(type, out parameters)) { ParametersCache[type] = parameters; } else { ParametersCache[type] = null; } return(parameters != null); }