-
Notifications
You must be signed in to change notification settings - Fork 0
Solid.Http.Extensions.ExceptionMapper Initialization
HX-Rd edited this page May 30, 2018
·
3 revisions
HXRd.Solid.Http.Extensions.ExceptionMapper is designed to work with Solid.Http and Solid.Http.Core.
-
MappersThis is aIEnumerable<IExceptionMapper>of custom mappers. See Extending how to create a custom mapper -
CustomDefaultMapperThis is aIExceptionMapper. You can choose to have a custom mapper as a default and then if you skip the generic type arguments, this mapper will be chosen -
UseModelStateExceptionsAsDefaultThis is a boolean and is false by default. If you set this to true, the exception will contain theModelStateas well.
The most basic example
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddSolidHttp()
.AddExceptionMappings();
}
}Using the model state exceptions
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
var customMapper = new CustomExceptionMapper();
services.AddSolidHttp()
.AddExceptionMappings(new ExceptionMappingOptions
{
UseModelStateExceptionsAsDefault = true
});
}
}Using a custom mapper and setting it as the default
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
var customMapper = new CustomExceptionMapper();
services.AddSolidHttp()
.AddExceptionMappings(new ExceptionMappingOptions
{
Mappers = new List<IExceptionMapper>
{
customMapper
},
CustomDefaultMapper = customMapper
});
}
}The most basic example
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddSolidHttpCore()
.AddExceptionMappings();
}
}Using the model state exceptions
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
var customMapper = new CustomExceptionMapper();
services.AddSolidHttpCore()
.AddExceptionMappings(new ExceptionMappingOptions
{
UseModelStateExceptionsAsDefault = true
});
}
}Using a custom mapper and setting it as the default
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
var customMapper = new CustomExceptionMapper();
services.AddSolidHttpCore()
.AddExceptionMappings(new ExceptionMappingOptions
{
Mappers = new List<IExceptionMapper>
{
customMapper
},
CustomDefaultMapper = customMapper
});
}
}