public async Task <IActionResult> Post(CancellationToken cancellationToken = default) { var authorizationResult = await _authorizationService.AuthorizeAsync(_httpContextAccessor.HttpContext.User, new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build()); var item = await CommandRegistryItem.ParseAsync(Request); if (!authorizationResult.Succeeded && !item.hasAllowAnonymousAttribute) { return(new UnauthorizedResult()); } var syncLock = _locks.GetOrAdd($"{item.PartitionKey}", id => new object()); lock (syncLock) _commandRegistry.TryToAdd(item); if (item.HasConflicts()) { await Observable.Zip(_commandRegistry .GetByCorrelationIds(item.ConflictingIds.Split(',')) .Select(x => x.Completed)); } dynamic result = default; try { result = await _mediator.Send(JsonConvert.DeserializeObject(item.Request, Type.GetType(item.RequestDotNetType)) as dynamic); item.Complete(); } catch (Exception e) { item.Error(); throw e; } return(new JsonResult(result)); }