-
Notifications
You must be signed in to change notification settings - Fork 0
2. Configuring the Pipeline
You can override some of the default processing options by providing the registration method the options setup action.
var builder = new ContainerBuilder();
builder.RegisterCommandBus(
new List<System.Reflection.Assembly>
{
// list the assemblies that contain your commands
},
opts =>
{
// set options
});The pipeline has 3 stages:
- Authorization
- Validation
- Execution
By default, when a command is received by the command bus, it is authorized (if an auth provider exists), validated (if a validator exists) and then passed to its handler.
By default, authorization is performed before validation. This can be switched by setting AuthorizeBeforeValidate to false in the options setup action.
opts =>
{
opts.AuthorizeBeforeValidate = false;
}By default, if authorization fails, a System.UnauthorizedAccessException is thrown. This can be overridden by providing a callback in the options setup action. The callback receives the command metadata as its only argument.
NOTE: If a callback is provided that does not throw an exception, the processing pipeline WILL continue to the next stage.
opts =>
{
opts.OnAuthorizationFailed = metadata =>
{
// custom auth failure logic
};
}By default, if an exception is thrown by a command handler, the exception is unhandled and allowed to bubble up into your application, allowing you to handle the exception either globally, or inside each handler.
If you want to provide common exception handling inside ALL command handlers, you can provide a callback in the options setup action. The callback is passed the exception that was thrown as its only argument.
opts =>
{
opts.OnHandlerException = ex =>
{
// custom exception handling
};
}