Exemplo n.º 1
0
        public async Task <ToDoItem> GetByIdAsync(int id)
        {
            var meta = new SafeCallServiceLogMetadata(
                this.headerAccessor.CorrelationId,
                typeof(ToDoRepository),
                nameof(this.GetByIdAsync));

            var command = new SafeCallServiceQuery <ToDoItem>(
                this.SimulatedDbCall,
                meta);

            return(await this.safeCallService.CallAsync(command));
        }
        public async Task <T> CallAsync <T>(SafeCallServiceQuery <T> command)
        {
            this.log.ForContext(command.Metadata.Context);

            try
            {
                using (this.log.BeginTimedOperation(command.Metadata.Name, identifier: command.Metadata.CorrelationId.ToString()))
                {
                    return(await command.Func.Invoke());
                }
            }
            catch (Exception ex)
            {
                this.log.Error(ex, $"Failed {command.Metadata.Context.Name}");
                return(default(T));
            }
        }