Skip to content

MicrosoftDependencyResolver.RegisterConstant(T?) method

Defined in

Type: MicrosoftDependencyResolver Namespace: Splat.Microsoft.Extensions.DependencyInjection Assembly: Splat.Microsoft.Extensions.DependencyInjection.dll

Applies to

net10.0, net10.0-desktop1.0, net10.0-browserwasm1.0, net9.0, net9.0, net9.0-browserwasm1.0, net9.0-desktop1.0, net8.0, net8.0, net8.0-ios17.5, net8.0-macos14.5, net8.0-macos14.5, net8.0-macos14.2, net8.0-macos14.2, net8.0-maccatalyst17.5, net8.0-maccatalyst17.5, net8.0-tvos17.2, net8.0-tvos17.2, net8.0-ios17.5, netstandard2.1, netstandard2.1, netstandard2.0, netstandard2.0, net481, net462

Overloads

  • 1. public void RegisterConstant<T>(T? value) where T : class
  • 2. public void RegisterConstant<T>(T? value, string? contract) where T : class

1. Overload

public void RegisterConstant<T>(T? value) where T : class

View source

Inherited documentation

These docs were inherited from IMutableDependencyResolver. The member doesn't override them on this type.

Summary: Registers a constant value of the specified reference type for later retrieval or use.

Type parameters

NameDescription
TThe reference type of the constant value to register.

Parameters

NameTypeDescription
valueT?The constant value to register. Can be null to represent the absence of a value.

2. Overload

public void RegisterConstant<T>(T? value, string? contract) where T : class

View source

Inherited documentation

These docs were inherited from IMutableDependencyResolver. The member doesn't override them on this type.

Summary: Registers a constant instance of the specified type for use in dependency resolution.

Type parameters

NameDescription
TThe type of the constant instance to register. Must be a reference type.

Parameters

NameTypeDescription
valueT?The constant instance to register. Can be null if null values are supported by the container.
contractstring?An optional contract name that uniquely identifies the registration. Can be null to register without a contract.

Remarks

Registering a constant ensures that the same instance is returned for all requests matching the specified type and contract. If a contract is provided, the constant is associated only with that contract; otherwise, it is registered for the type without a contract.