In this section, I would like to explain what it is for and how it can work.
To begin with, it would be necessary to specify that such an idea has been around since I started my career as a developer. Surely everyone has faced a situation when during the execution of a flow, some errors or exceptions occur that need to be handled and a response returned that is understandable to each participant in the execution flow. The main reason behind the implementation was the principle that no method implemented in the code should throw an exception, the only and most correct approach is to handle it and return it in a relatively easily understood form.
Respectively, this repository/package aims to provide the possibility to manage the response that must be returned as a response to the execution of a method or flow. In other words, a single type of structured response is easy to understand and further exposed, with the possibility of having full control of the messages that are returned. Namely messages, the concept is realized in the form of messages, 6 general types of messages such as:
• Information (Info);
• Warning (Warning);
• Error (Error);
• Nonexistent data (NotFound);
• Restricted access (AccessDenied);
• Exception in the execution process (Exception).
Generally, access is done by calling Result
and Success
or Failure
methods. These two methods are basic and are called initially after all the additional information required has been set.
To be easier to use, but also flexible, extensions have been added to the current solution to set error messages such as:
-
WithMessage
; -
WithKeyCode
; -
WithCodeMessage
; -
WithError
; -
WithErrors
. In some cases when you may have the necessity to add in the result additional information like the link between the code execution method and data store name: stored procedure, function or table, etc; in code/result is defined objectRelatedObject
where this information can be stored and returned to the caller.
For more efficient use, in some cases, you may need to execute some custom actions/functions after a successful or failed execution request. In that case, was added extension methods (ActionOnSuccess
, ActionOnFailure
, ActionOn
, ExecuteAction
, FunctionOnSuccess
, FunctionOnFailure
, FunctionOn
, ExecuteFunction
) which allow you to execute this action/function like insert log when execution has a status equal to failure.
In addition to those mentioned above, within the solution, there is also another series of methods that will surely be helpful. In particular, an implementation is presented that allows the message to be returned in XML form, as in previous versions of web services (SOAP), JSON cannot be returned using XML or in other words, a dynamic response/message cannot be returned.
For more technical information, please consult the available documentation and use terms from the GitHub repository.
Link to the repository:
I-RzR-I
/
AggregatedGenericResultMessage
This repository can help you to aggregate all results from an API or method in one. So as a result of this, you will have control over all responses given to the caller.
Note This repository is developed in .netstandard2+ with support for SOAP service results mainly used in the .net framework (current support 4.5, 4.6.1 - 4.8)
The goal of this repository is to offer the possibility to manage and agree on the answers received as a result of the execution of a method or a process.
In other words, it offers the possibility to use a single(general) response, structured and easier parsed model for the executed methods As a result, you can have control over the messages and types of messages that will be obtained.
By currently following, 6 general types of messages (Info
, Warning
, Error
, NotFound
, AccessDenied
, Exception
) are implemented that can be returned to the caller
As you can see in the MessageType
enum, there are 9 types of messages, for all 3 (Info
, Warning
, Error
) types previously…
Top comments (0)