public CommandMethodMapping(Type domainObjectType, Type commandType, MethodInfo method, bool awaitable, CommandMethodMappingKind kind) { Precondition.For(domainObjectType, nameof(domainObjectType)).NotNull(); Precondition.For(commandType, nameof(commandType)).NotNull(); Precondition.For(method, nameof(method)).NotNull(); DomainObjectType = domainObjectType; CommandType = commandType; Method = method; Kind = kind; Awaitable = awaitable; }
private static CommandMethodMapping ToMapping(Type domainObjectType, MethodInfo nfo) { Type type = nfo.GetParameters().First().ParameterType; Type attribType = GetBehaviorAttribute(nfo); CommandMethodMappingKind kind = CreateAttributeType.IsAssignableFrom(attribType.GetTypeInfo()) ? CommandMethodMappingKind.Create : CommandMethodMappingKind.Update; bool awaitable = Task.IsAssignableFrom(nfo.ReturnType.GetTypeInfo()); var result = new CommandMethodMapping(domainObjectType, type, nfo, awaitable, kind); return(result); }
public async Task <IDomainObject> InvokeAsync(Type domainObjectType, ICommand cmd, CommandMethodMappingKind kind, ICollection <CommandMethodMapping> methodMappings) { IDomainObject domainObject; if (kind == CommandMethodMappingKind.Create) { domainObject = repository.New(domainObjectType, cmd.DomainObjectId); } else { if (kind == CommandMethodMappingKind.UpdateWithoutHistory) { logger.LogTrace("Creating new \"{domainObjectType}\" with id {domainObjectId}", domainObjectType, cmd.DomainObjectId); domainObject = repository.New(domainObjectType, cmd.DomainObjectId); } else { logger.LogTrace("Getting existing \"{domainObjectType}\" with id {domainObjectId}", domainObjectType, cmd.DomainObjectId); domainObject = await repository.Get(cmd.DomainObjectId, domainObjectType); } } if (policyValidator.CheckPolicies(domainObject, cmd, methodMappings.Select(x => x.Method).ToArray())) { logger.LogTrace("Applying command on \"{domainObjectType}\" with id {domainObjectId}", domainObjectType, cmd.DomainObjectId); await ApplyCommands(domainObject, cmd, methodMappings); } else { logger.LogTrace("Policy prevented command on \"{domainObjectType}\" with id {domainObjectId}", domainObjectType, cmd.DomainObjectId); } return(domainObject); }
public async Task <IDomainObject> InvokeAsync(Type domainObjectType, ICommand cmd, CommandMethodMappingKind kind, ICollection <CommandMethodMapping> methodMappings) { IDomainObject domainObject; if (kind == CommandMethodMappingKind.Create) { domainObject = repository.New(domainObjectType, cmd.DomainObjectId); } else { if (kind == CommandMethodMappingKind.UpdateWithoutHistory) { domainObject = repository.New(domainObjectType, cmd.DomainObjectId); } else { domainObject = await repository.Get(cmd.DomainObjectId, domainObjectType); } } if (policyValidator.CheckPolicies(domainObject, cmd, methodMappings.Select(x => x.Method).ToArray())) { await ApplyCommands(domainObject, cmd, methodMappings); } return(domainObject); }