/// <inheritdoc /> public async Task <ArtifactId> ResolveId(MicroserviceAddress runtime, AggregateRootIdOrAlias idOrAlias) { if (!idOrAlias.IsAlias) { return(idOrAlias.Id); } var aggregateRoots = await _managementClient.GetAll(runtime).ConfigureAwait(false); var aggregateRoot = aggregateRoots.FirstOrDefault(_ => WithAlias(_, idOrAlias)); if (aggregateRoot == default) { throw new NoAggregateRootWithId(idOrAlias.Alias); } return(aggregateRoot.AggregateRoot.Identifier.Id); }
/// <summary> /// Gets the Aggregate Root id. /// </summary> /// <param name="runtime">The Runtime microservice address.</param> /// <param name="idOrAlias">The AggregateRootId Id or Alias.</param> /// <returns>A <see cref="Task{TResult}"/> that, when resolved, returns the <see cref="ArtifactId"/>.</returns> protected Task <ArtifactId> GetAggregateRootId(MicroserviceAddress runtime, AggregateRootIdOrAlias idOrAlias) => _aggregateRootIdResolver.ResolveId(runtime, idOrAlias);
static bool WithAlias(AggregateRootWithTenantScopedInstances root, AggregateRootIdOrAlias idOrAlias) => !root.AggregateRoot.Alias.Equals(AggregateRootAlias.NotSet) && root.AggregateRoot.Alias.Equals(idOrAlias.Alias);