Welcome to the twenty episode of my course “Becoming a software developer” in which we will implement our custom “handler” that will be responsible for executing the given methods, dealing with exceptions etc.
All of the materials including videos and sample projects can be downloaded from here.
The source code repository is being hosted on GitHub.
Scope
- Handler
Abstract
Handler
In the last 2 episodes, we dealt with exceptions. It’s high time to actually complete this story and also extend the rather simple extension handling middleware. In order to achieve that, we will implement our custom handler using the so-called Fluent API technique that will allow defining the flow of the methods (e.g. some more or less complicated business logic) into a nicely written method chain. Such method chaining is another programming technique and the goal of this episode is to actually learn 2 things – how the Fluent API can be implemented, but also how you can switch from a typical, procedural style of writing the code into the more expressive one.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
public async Task HandleAsync(Login command) => await _handler .Validate(async () => ...) .Run(async () => await _userService.LoginAsync(command.Email, command.Password)) .Next() .Run(async () => { var user = await _userService.GetAsync(command.Email); var jwt = _jwtHandler.CreateToken(user.Id, user.Role); _cache.SetJwt(command.TokenId, jwt); }) .OnCustomError(async exception => ...) .OnError(async exception => ...) .Next() .Run(async => ...) .ExecuteAllAsync(); } |
Next
In the next episode, we will store the application data using MongoDB which is a NoSQL database.
Pingback: Dew Drop - June 8, 2017 (#2496) - Morning Dew
Visit the best platform for bingo bash facebook gaming. These are awesome. The mentioned website has free hack for generating free bingo bash chips. Thanks
I think blogging to relieve stress on the brain and save the memories.