/// <summary> /// Adds an exception mapping scheme which uses strongly-typed settings of <typeparamref name="TOptions"/> /// and a set of mapping conventions of <typeparamref name="TConventionService"/> to handle exception. This /// method passes custom parameters to the constructor of <typeparamref name="THandler"/>. /// </summary> /// <typeparam name="TOptions">The type of the settings consumed by the scheme.</typeparam> /// <typeparam name="TConventionService">The mapping convention service type.</typeparam> /// <typeparam name="THandler">The type of the scheme implementer.</typeparam> /// <param name="builder">The builder.</param> /// <param name="name">The name of the scheme to be added.</param> /// <param name="configure">The action to configure scheme options.</param> /// <param name="parameters">The custom parameters to pass into the handler.</param> public static ExceptionMappingBuilder AddParameterizedScheme <TOptions, TConventionService, THandler>( this ExceptionMappingBuilder builder, string name, Action <TOptions> configure, params object[] parameters) where TOptions : ExceptionMappingSchemeOptions, new() where TConventionService : class where THandler : ExceptionHandler <TOptions, TConventionService> { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } if (configure == null) { throw new ArgumentNullException(nameof(configure)); } if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } builder.Services.Configure <TOptions>(name, opt => opt.SchemeName = name); builder.AddParameterizedScheme <THandler>(name, parameters); builder.Services.Configure(name, configure); return(builder); }
/// <summary> /// Adds an exception mapping scheme which uses strongly-typed settings of <typeparamref name="TOptions"/> /// and a set of mapping conventions of <typeparamref name="TConventionService"/> to handle exception. This /// method passes custom parameters to the constructor of <typeparamref name="THandler"/>. /// </summary> /// <typeparam name="TOptions">The type of the settings consumed by the scheme.</typeparam> /// <typeparam name="TConventionService">The mapping convention service type.</typeparam> /// <typeparam name="THandler">The type of the scheme implementer.</typeparam> /// <param name="builder">The builder.</param> /// <param name="name">The name of the scheme to be added.</param> /// <param name="parameters">The custom parameters to pass into the handler.</param> public static ExceptionMappingBuilder AddParameterizedScheme <TOptions, TConventionService, THandler>( this ExceptionMappingBuilder builder, string name, params object[] parameters) where TOptions : ExceptionMappingSchemeOptions, new() where TConventionService : class where THandler : ExceptionHandler <TOptions, TConventionService> => builder.AddParameterizedScheme <TOptions, TConventionService, THandler>(name, _ => { }, parameters);