Skip to main content

Definition

Assembly: Microsoft.Extensions.DependencyInjection.Abstractions.dll Namespace: Microsoft.Extensions.DependencyInjection

Syntax

Microsoft.Extensions.DependencyInjection.IServiceCollection

Summary

This type is defined in Microsoft.Extensions.DependencyInjection.Abstractions.

Remarks

See Microsoft documentation for more information about the rest of the API.

Methods

AddConfigurationBase Extension

Extension method from Microsoft.Extensions.DependencyInjection.EasyAF_Configuration_IServiceCollectionExtensions
Adds a configuration class that inherits from ConfigurationBase to the service collection. The configuration is bound from the specified configuration section and registered as both the specific type and the base ConfigurationBase type for dependency injection.

Syntax

public static TConfiguration AddConfigurationBase<TConfiguration>(Microsoft.Extensions.DependencyInjection.IServiceCollection services, Microsoft.Extensions.Configuration.IConfiguration configuration, string configSectionName) where TConfiguration : CloudNimble.EasyAF.Configuration.ConfigurationBase

Parameters

NameTypeDescription
servicesMicrosoft.Extensions.DependencyInjection.IServiceCollectionThe service collection to add the configuration to.
configurationMicrosoft.Extensions.Configuration.IConfigurationThe configuration instance to bind from.
configSectionNamestringThe name of the configuration section to bind from.

Returns

Type: TConfiguration The bound configuration instance for immediate use or further configuration.

Type Parameters

  • TConfiguration - The type of configuration class that inherits from ConfigurationBase.

Examples

// In Program.cs or Startup.cs
var myConfig = builder.Services.AddConfigurationBase&lt;MyAppConfiguration&gt;(
    builder.Configuration,
    "AppSettings"
);

// The configuration can now be injected as either type:
// [Inject] public MyAppConfiguration Config { get; set; }
// [Inject] public ConfigurationBase BaseConfig { get; set; }

AddHttpClients Extension

Extension method from Microsoft.Extensions.DependencyInjection.EasyAF_Http_IServiceCollectionExtensions
Adds HTTP clients to the service collection based on configuration properties marked with HttpEndpointAttribute. Uses the default HttpHandlerMode from the configuration.

Syntax

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddHttpClients<TConfig, TMessageHandler>(Microsoft.Extensions.DependencyInjection.IServiceCollection services, TConfig config) where TConfig : CloudNimble.EasyAF.Configuration.ConfigurationBase where TMessageHandler : System.Net.Http.DelegatingHandler

Parameters

NameTypeDescription
servicesMicrosoft.Extensions.DependencyInjection.IServiceCollectionThe service collection to add HTTP clients to.
configTConfigThe configuration instance containing endpoint definitions.

Returns

Type: Microsoft.Extensions.DependencyInjection.IServiceCollection The service collection for method chaining.

Type Parameters

  • TConfig - The configuration type that contains HTTP endpoint definitions.
  • TMessageHandler - The type of message handler to add to the HTTP clients.

AddHttpClients Extension

Extension method from Microsoft.Extensions.DependencyInjection.EasyAF_Http_IServiceCollectionExtensions
Adds HTTP clients to the service collection based on configuration properties marked with HttpEndpointAttribute. Allows explicit specification of the HttpHandlerMode for message handler configuration.

Syntax

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddHttpClients<TConfig, TMessageHandler>(Microsoft.Extensions.DependencyInjection.IServiceCollection services, TConfig config, CloudNimble.EasyAF.Core.HttpHandlerMode httpHandlerMode) where TConfig : CloudNimble.EasyAF.Configuration.ConfigurationBase where TMessageHandler : System.Net.Http.DelegatingHandler

Parameters

NameTypeDescription
servicesMicrosoft.Extensions.DependencyInjection.IServiceCollectionThe service collection to add HTTP clients to.
configTConfigThe configuration instance containing endpoint definitions.
httpHandlerModeCloudNimble.EasyAF.Core.HttpHandlerModeSpecifies how message handlers should be configured for the HTTP clients.

Returns

Type: Microsoft.Extensions.DependencyInjection.IServiceCollection The service collection for method chaining.

Type Parameters

  • TConfig - The configuration type that contains HTTP endpoint definitions.
  • TMessageHandler - The type of message handler to add to the HTTP clients.

Examples

// Register HTTP clients with custom message handler
services.AddHttpClients&lt;MyConfiguration, MyAuthHandler&gt;(config, HttpHandlerMode.Add);

// This will automatically register HttpClient instances for all properties
// in MyConfiguration that are marked with [HttpEndpoint]