示例#1
0
        private static void Main(string[] args)
        {
            // DI

            var userRepository = new UserRepository();

            var command = new GetUserCommand(userRepository);

            WriteResponseToCase(command);

            ReturnResultCase(command);
        }
示例#2
0
        private static void ReturnResultCase(GetUserCommand command)
        {
            var commandResponse = command.GetUser("User1");

            var response = commandResponse
                           .OnSuccess(user =>
            {
                return(Task.FromResult(user.Username));
            })
                           .OnFailure((error, user) =>
            {
                return(Task.FromResult(error));
            });

            Console.WriteLine(response);
        }
示例#3
0
        private static void WriteResponseToCase(GetUserCommand command)
        {
            var commandResponseNoResult = command.GetUserWriteNoResult("User1");

            commandResponseNoResult
            .OnSuccess(user =>
            {
                // Write to response request body

                return(Task.CompletedTask);
            })
            .OnFailure((error, user) =>
            {
                // Write to response request body with specific code

                return(Task.CompletedTask);
            });
        }