,System.Type,System.String)} ,System.Type)} )} ,System.String)}
DryIocDependencyResolver.Register(Func
Defined in
Type: DryIocDependencyResolver
Namespace: Splat.DryIoc
Assembly: Splat.DryIoc.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-ios17.5, net8.0-tvos17.2, net8.0-tvos17.2, netstandard2.1, netstandard2.1, netstandard2.0, netstandard2.0, net471, net481, net462
Overloads¶
- 1.
public virtual void Register(Func<object?> factory, Type? serviceType, string? contract) - 2.
public void Register(Func<object?> factory, Type? serviceType) - 3.
public void Register<T>(Func<T?> factory) - 4.
public void Register<T>(Func<T?> factory, string? contract)
1. Overload¶
public virtual void Register(Func<object?> factory, Type? serviceType, string? contract)
Inherited documentation
These docs were inherited from IMutableDependencyResolver. The member doesn't override them on this type.
Summary: Registers a factory method for creating instances of a specified service type and contract.
Parameters
| Name | Type | Description |
|---|---|---|
factory | Func | A delegate that returns an instance of the service to register. Cannot be null. |
serviceType | Type? | The type of the service to register. If null, the type is inferred from the factory's return value. |
contract | string? | An optional contract name that distinguishes this registration from others of the same service type. Can be null or empty for the default contract. |
Remarks
Use this method to register services with custom creation logic, such as when dependencies or configuration are required at instantiation. If multiple registrations exist for the same service type and contract, the most recent registration may take precedence, depending on the container's behavior.
2. Overload¶
public void Register(Func<object?> factory, Type? serviceType)
Inherited documentation
These docs were inherited from IMutableDependencyResolver. The member doesn't override them on this type.
Summary: Registers a factory method for creating instances of the specified service type.
Parameters
| Name | Type | Description |
|---|---|---|
factory | Func | A delegate that returns an instance of the service. The delegate may return null if appropriate for the service. |
serviceType | Type? | The type of the service to register. If null, the type may be inferred from the factory's return type. |
Remarks
Use this method to provide custom logic for creating service instances. If serviceType is null, the registration mechanism may attempt to infer the service type from the factory delegate's return type.
3. Overload¶
public void Register<T>(Func<T?> factory)
Inherited documentation
These docs were inherited from IMutableDependencyResolver. The member doesn't override them on this type.
Summary: Register a function with the resolver which will generate an object for the specified service type. Most implementations will use a stack based approach to allow for multiple items to be registered.
Type parameters
| Name | Description |
|---|---|
T | The type which is used for the registration. |
Parameters
| Name | Type | Description |
|---|---|---|
factory | Func | The factory function which generates our object. |
Remarks
This generic method is preferred over the non-generic Register method for better performance and type safety. It enables optimizations in resolvers like GlobalGenericFirstDependencyResolver which use static generic containers for zero-cost service resolution.
4. Overload¶
public void Register<T>(Func<T?> factory, string? contract)
Inherited documentation
These docs were inherited from IMutableDependencyResolver. The member doesn't override them on this type.
Summary: Register a function with the resolver which will generate an object for the specified service type. Optionally a contract can be registered which will indicate that registration will only work with that contract. Most implementations will use a stack based approach to allow for multiple items to be registered.
Type parameters
| Name | Description |
|---|---|
T | The type which is used for the registration. |
Parameters
| Name | Type | Description |
|---|---|---|
factory | Func | The factory function which generates our object. |
contract | string? | A contract value which will indicates to only generate the value if this contract is specified. |
Remarks
This generic method is preferred over the non-generic Register method for better performance and type safety. It enables optimizations in resolvers like GlobalGenericFirstDependencyResolver which use static generic containers for zero-cost service resolution.