/// <summary> /// Runs an action on <see cref="SolidHttpBuilder" />. /// </summary> /// <param name="services">The <see cref="IServiceCollection" /> that Solid.Http.Core has been, or will be, added to.</param> /// <param name="buildAction">An action to run on <see cref="SolidHttpBuilder" />.</param> /// <returns>The <see cref="IServiceCollection" /> so that additional calls can be chained.</returns> public static IServiceCollection ConfigureSolidHttp(this IServiceCollection services, Action <SolidHttpBuilder> buildAction) { var builder = new SolidHttpBuilder(services); buildAction(builder); return(services); }
/// <summary> /// Adds a JSON deserializer to the <see cref="SolidHttpBuilder" />. /// </summary> /// <param name="builder">The <see cref="SolidHttpBuilder" /> being extended.</param> /// <typeparam name="TDeserializer">The type of JSON deserializer.</typeparam> /// <returns>The <see cref="SolidHttpBuilder" /> so that additional calls can be chained.</returns> public static SolidHttpBuilder AddJsonDeserializer <TDeserializer>(this SolidHttpBuilder builder) where TDeserializer : class, IJsonDeserializer { builder.Services.RemoveAll <IJsonDeserializer>(); builder.Services.AddSingleton <IJsonDeserializer, TDeserializer>(); builder.AddDeserializer(p => p.GetService <IJsonDeserializer>()); return(builder); }
/// <summary> /// Add SolidHttp to the service collection using the default features (json) /// </summary> /// <param name="services">The service collection</param> /// <param name="action">A configuration action</param> /// <returns>IServiceCollection</returns> public static IServiceCollection AddSolidHttp(this IServiceCollection services, Action <ISolidHttpBuilder> action) { var core = null as ISolidHttpCoreBuilder; services.AddSolidHttpCore(b => core = b); core.AddJson(); var builder = new SolidHttpBuilder(core); action(builder); return(services); }
/// <summary> /// Adds JSON deserialization to <see cref="SolidHttpBuilder" />. /// <para>This JSON deserialization uses System.Text.Json.</para> /// </summary> /// <param name="builder">The <see cref="SolidHttpBuilder" /> that is being extended.</param> /// <param name="configureOptions">A delegate used to configure <see cref="SolidHttpJsonOptions" />.</param> /// <returns>The <see cref="SolidHttpBuilder" /> so that additional calls can be chained.</returns> public static SolidHttpBuilder AddJson(this SolidHttpBuilder builder, Action <SolidHttpJsonOptions> configureOptions) { builder.AddJson(); builder.Services.ConfigureSolidHttpJson(configureOptions); return(builder); }
/// <summary> /// Adds JSON deserialization to <see cref="SolidHttpBuilder" />. /// <para>This JSON deserialization uses System.Text.Json.</para> /// </summary> /// <param name="builder">The <see cref="SolidHttpBuilder" /> that is being extended.</param> /// <returns>The <see cref="SolidHttpBuilder" /> so that additional calls can be chained.</returns> public static SolidHttpBuilder AddJson(this SolidHttpBuilder builder) { builder.AddJsonDeserializer <SystemTextJsonDeserializer>(); return(builder); }
/// <summary> /// Adds XML deserialization to <see cref="SolidHttpBuilder" />. /// <para>This XML deserialization uses <see cref="DataContractSerializer" />.</para> /// </summary> /// <param name="builder">The <see cref="SolidHttpBuilder" /> that is being extended.</param> /// <returns>The <see cref="SolidHttpBuilder" /> so that additional calls can be chained.</returns> public static SolidHttpBuilder AddXml(this SolidHttpBuilder builder) { builder.Services.TryAddSingleton <DataContractXmlDeserializer>(); builder.AddDeserializer(p => p.GetService <DataContractXmlDeserializer>()); return(builder); }
/// <summary> /// Adds <see cref="ZipArchive" /> deserialization to <see cref="SolidHttpBuilder" />. /// <para>This ZIP deserialization uses System.IO.Compression.</para> /// </summary> /// <param name="builder">The <see cref="SolidHttpBuilder" /> that is being extended.</param> /// <returns>The <see cref="SolidHttpBuilder" /> so that additional calls can be chained.</returns> public static SolidHttpBuilder AddZip(this SolidHttpBuilder builder) { builder.Services.TryAddSingleton <ZipArchiveDeserializer>(); builder.AddDeserializer(p => p.GetService <ZipArchiveDeserializer>()); return(builder); }
/// <summary> /// Adds JSON deserialization to <see cref="SolidHttpBuilder" />. /// <para>This JSON deserialization uses Newtonsoft.Json.</para> /// </summary> /// <param name="builder">The <see cref="SolidHttpBuilder" /> that is being extended.</param> /// <returns>The <see cref="SolidHttpBuilder" /> so that additional calls can be chained.</returns> public static SolidHttpBuilder AddNewtonsoftJson(this SolidHttpBuilder builder) { builder.AddJsonDeserializer <NewtonsoftJsonDeserializer>(); return(builder); }