,System.Type)} ,System.Type,System.String)} )} ,System.String)}
AutofacDependencyResolver.Register(Func
Defined in
Type: AutofacDependencyResolver
Namespace: Splat.Autofac
Assembly: Splat.Autofac.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) - 2.
public virtual void Register(Func<object?> factory, Type? serviceType, string? contract) - 3.
public void Register<T>(Func<T?> factory) - 4.
public void Register<T>(Func<T?> factory, string? contract) - 5.
public void Register<TService, TImplementation>() where TService : class where TImplementation : class, TService, new() - 6.
public void Register<TService, TImplementation>(string? contract) where TService : class where TImplementation : class, TService, new()
1. Overload¶
Deprecated
Because Autofac 5+ containers are immutable, this method should not be used by the end-user.
Attributes: [Obsolete("Because Autofac 5+ containers are immutable, this method should not be used by the end-user.")]
public virtual void Register(Func<object?> factory, Type? serviceType)
Summary: Important: Because Autofac 5+ containers are immutable, this method should not be used by the end-user. It is still needed to satisfy ReactiveUI initialization procedure. Register a function with the resolver which will generate a object for the specified service type. Most implementations will use a stack based approach to allow for multiple items to be registered.
Parameters
| Name | Type | Description |
|---|---|---|
factory | Func | The factory function which generates our object. |
serviceType | Type? | The type which is used for the registration. |
2. Overload¶
Deprecated
Because Autofac 5+ containers are immutable, this method should not be used by the end-user.
Attributes: [Obsolete("Because Autofac 5+ containers are immutable, this method should not be used by the end-user.")]
public virtual void Register(Func<object?> factory, Type? serviceType, string? contract)
Summary: Important: Because Autofac 5+ containers are immutable, this method should not be used by the end-user. It is still needed to satisfy ReactiveUI initialization procedure. Register a function with the resolver which will generate a object for the specified service type. A contract is 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.
Parameters
| Name | Type | Description |
|---|---|---|
factory | Func | The factory function which generates our object. |
serviceType | Type? | The type which is used for the registration. |
contract | string? | A contract value which indicates to only generate the value if this contract is specified. |
3. Overload¶
Deprecated
Because Autofac 5+ containers are immutable, this method should not be used by the end-user.
Attributes: [Obsolete("Because Autofac 5+ containers are immutable, this method should not be used by the end-user.")]
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¶
Deprecated
Because Autofac 5+ containers are immutable, this method should not be used by the end-user.
Attributes: [Obsolete("Because Autofac 5+ containers are immutable, this method should not be used by the end-user.")]
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.
5. Overload¶
Deprecated
Because Autofac 5+ containers are immutable, this method should not be used by the end-user.
Attributes: [Obsolete("Because Autofac 5+ containers are immutable, this method should not be used by the end-user.")]
public void Register<TService, TImplementation>() where TService : class where TImplementation : class, TService, new()
Inherited documentation
These docs were inherited from IMutableDependencyResolver. The member doesn't override them on this type.
Summary: Registers a service type and its implementation for dependency resolution.
Type parameters
| Name | Description |
|---|---|
TService | The interface or base class type to register as a service. Must be a reference type. |
TImplementation | The concrete implementation type to instantiate when resolving the service. Must be a reference type, implement TService, and have a public parameterless constructor. |
Remarks
Subsequent requests for TService will resolve to instances of TImplementation. If the service type is already registered, this method may overwrite the existing registration depending on the implementation.
6. Overload¶
Deprecated
Because Autofac 5+ containers are immutable, this method should not be used by the end-user.
Attributes: [Obsolete("Because Autofac 5+ containers are immutable, this method should not be used by the end-user.")]
public void Register<TService, TImplementation>(string? contract) where TService : class where TImplementation : class, TService, new()
Inherited documentation
These docs were inherited from IMutableDependencyResolver. The member doesn't override them on this type.
Summary: Registers a service implementation with an optional contract name for dependency resolution.
Type parameters
| Name | Description |
|---|---|
TService | The type of the service to register. Must be a reference type. |
TImplementation | The concrete implementation type to register for the service. Must be a reference type with a public parameterless constructor. |
Parameters
| Name | Type | Description |
|---|---|---|
contract | string? | An optional contract name that distinguishes this registration from others of the same service type. Specify null to register the implementation without a contract. |
Remarks
Use this method to associate a service interface or base class with a specific implementation, optionally under a contract name. This enables resolving different implementations of the same service type by contract. If multiple implementations are registered for the same service and contract, the behavior may depend on the container's resolution strategy.