Method ConfigureServices
- Namespace
- Ploch.CommandLine.Spectre
- Assembly
- Ploch.CommandLine.Spectre.dll
ConfigureServices(Action<IServiceCollection>)
Configures the services for the application.
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = "This method is a part of the public API and is intended for use by consumers of the AppBuilder class.")]
public AppBuilder ConfigureServices(Action<IServiceCollection> servicesConfigurator)
Parameters
servicesConfiguratorAction<IServiceCollection>An action to configure the IServiceCollection for dependency injection.
Returns
- AppBuilder
The current instance of AppBuilder for method chaining.
Remarks
This method allows customisation of the application's services by providing a delegate that operates on the IServiceCollection. It is useful for registering dependencies and configuring services required by the application.
Calls accumulate: every delegate passed to either overload is applied, in the order it was added, matching the additive behaviour of ConfigureServices(Action<HostBuilderContext, IServiceCollection>). The order is shared with ConfigureHost(Action<IHostBuilder>), so a registration made here takes precedence over one made by an earlier ConfigureHost(Action<IHostBuilder>) call and yields to one made by a later call. See ConfigureCommandApp(Action<IConfigurator>) for the full ordering guarantee.
The host these services go into is built once a run reaches command resolution and is never started by
the library, so a hosted service registered here — with AddHostedService, for instance — does not
run; see ConfigureCommandApp(Action<IConfigurator>).
Exceptions
- ArgumentNullException
Thrown when
servicesConfiguratoris null.
ConfigureServices(Action<HostBuilderContext, IServiceCollection>)
Configures the services for the application using the specified configurator.
public AppBuilder ConfigureServices(Action<HostBuilderContext, IServiceCollection> servicesConfigurator)
Parameters
servicesConfiguratorAction<HostBuilderContext, IServiceCollection>An action that allows customisation of the service collection. The action provides access to the HostBuilderContext and IServiceCollection for configuring services.
Returns
- AppBuilder
The current instance of AppBuilder to allow method chaining.
Remarks
This method enables the addition or modification of services in the application's dependency injection container. It supports advanced configuration scenarios by providing access to the hosting context.
Calls accumulate: every delegate passed to either overload is applied, in the order it was added, matching the additive behaviour of ConfigureServices(Action<HostBuilderContext, IServiceCollection>). The order is shared with ConfigureHost(Action<IHostBuilder>), so a registration made here takes precedence over one made by an earlier ConfigureHost(Action<IHostBuilder>) call and yields to one made by a later call. See ConfigureCommandApp(Action<IConfigurator>) for the full ordering guarantee.
The host these services go into is built once a run reaches command resolution and is never started by
the library, so a hosted service registered here — with AddHostedService, for instance — does not
run; see ConfigureCommandApp(Action<IConfigurator>).
Exceptions
- ArgumentNullException
Thrown when
servicesConfiguratoris null.