Let's apply constructor injection to our ACME registration service. This time we will be refactoring the REST package, starting with the Register endpoint. You may remember that Register is one of three endpoints in our service, the others being Get and List.
The Register endpoint has three responsibilities:
- Validate the registration is complete and valid
- Call the currency conversion service to convert the registration price to the currency requested in the registration
- Save the registration and the converted registration price into the database
The code for our Register endpoint currently looks as shown in the following code:
// RegisterHandler is the HTTP handler for the "Register" endpoint
// In this simplified example we are assuming all possible errors
// are user errors and returning "bad request" HTTP 400.
// There...