Handlers, Pipelines, Plugins, Rules, Mappers (22%) Flashcards
Which design pattern follows the handler chain ?
The chain of responsibility design pattern
What is the responsibility of each handler when its processing is complete ?
Calling the next handler in the chain or terminate the chain immediately
What is the sole entry point into a handler ?
The “Execute” method
Two handlers are part of the same handler chain if:
they both declare the same parameter and result object types
True or false.
As a best practice, all handlers should inherit from the HandlerBase class ?
True
Why do we need to decorate handlers with the DependencyName attribute ?
This allows the handler to be retrieved by name via the dependency locator.
Which method should continue an handler chain or break it ?
The the Execute method
What should be the last line of code of your handler to execute the next one?
return this.NextHandler.Execute(unitOfWork, parameter, result);
What should be the last line of code of your handler to break the handler chain?
return result;
What are mappers ?
Mappers are extension points of the Optimizely B2B Commerce platform.
What is the purposes of mappers?
Bridge the gap between the API presentation layer and the business logic layer (services) for both input and output.
Is it possible to inherit from Optimizely’s mapper classes ?
Yes
When you derive from a mapper class, where are you allowed to read additional information from the HTTP request and provide the information to the parameters object that will be used during the next handler chain ?
In the MapParameter method
True or false.
In a mapper, you should read information using the HttpContext directly in your handler chain extension?
False. The best practice is to collect all the information read from the HTTP request in the mapper and send it as properties to the parameters object for the handle chain.
Which method of a mapper allows us to intervene on the feedback of the handler chain (service result) and to pass it to the response object (API model) ?
The MapResult method
Where should the majority of customizations and modifications be located?
In the extensions of the handler chain and/or pipelines that are called during the execution of this handler chain.
Where its the appropriate place to add properties to the API model, for any entity field that you would like to have available on the frontend ?
In a mapper class
Where is the appropriate place to add “display” properties that can become handy on the frontend ?
In a mapper class
Why should you move the logic of the private functions from the handler class to a service?
- The values that these methods compute are possibly reusable in other places in the application.
- Using a service will eliminate the duplication of code and make it usable elsewhere.
- The service is also testable with unit tests, if the logic is complex enough and you want to perform test coverage.
Pipelines are very similar to handler chains. Which statements are not true ? Pick 2.
- Both follows the principles of the chain of responsibility design pattern.
- Both can interrupt the execution.
- A pipeline is made of classes, which are called “pipes” and handler chains are made of classes called handlers.
- No need to specify the DependencyName attribute on a pipe class
- The Execute method of an handler class simply returns the result.
Both can interrupt the execution is false. Unlike a handler class, a pipe class cannot interrupt the execution of the rest of the pipeline.
The Execute method of an handler class simply returns the result is false. The Execute method of a pipe class simply returns the result. No need to call the next pipe class.
What is the responsibility of the mapper ?
The Mapper is responsible for transcribing the API Parameter to an object that the service layer can use, usually named ServiceParameter.
What are the responsibilities of controllers?
Managing requests and responses
True or False. Controllers are responsible to apply business logic?
False. They are responsible for managing the flow of the API request through the Mapper, then to the service, back into the mapper and send a response.
Which are the 2 responsibilities of the mappers?
- Mapping objects from the presentation layer (API model) to objects that the service layer can use (Service Parameter)
- Mapping back the Service Result into an API model that the controller can send back into the response
How do you create an handler chain?
Inject the HandlerFactory responsible for creating handler chains
Call the first Handler’s Execute method, which in turn will call the next Handler’s Execute method and so on