Interface IServiceResolverBase
interface used by fastendpoints for resolving services from the DI container. implement this interface and register the implementation in MS DI for customizing service resolving.
Namespace: FastEndpoints
Assembly: FastEndpoints.dll
Syntax
public interface IServiceResolverBase
Methods
CreateScope()
if you'd like to resolve scoped or transient services from the MS DI container, obtain a service scope from this method and dispose the scope when the work is complete.
using var scope = CreateScope();
var scopedService = scope.Resolve<MyService>();
Declaration
IServiceScope CreateScope()
Returns
Type | Description |
---|---|
IServiceScope |
Resolve(Type)
resolve an instance for the given type from the dependency injection container. will throw if unresolvable.
Declaration
object Resolve(Type typeOfService)
Parameters
Type | Name | Description |
---|---|---|
Type | typeOfService | the type of the service to resolve |
Returns
Type | Description |
---|---|
object |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if requested service cannot be resolved |
Resolve<TService>()
resolve an instance for the given type from the dependency injection container. will throw if unresolvable.
Declaration
TService Resolve<TService>() where TService : class
Returns
Type | Description |
---|---|
TService |
Type Parameters
Name | Description |
---|---|
TService | the type of the service to resolve |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if requested service cannot be resolved |
TryResolve(Type)
try to resolve an instance for the given type from the dependency injection container. will return null if unresolvable.
Declaration
object? TryResolve(Type typeOfService)
Parameters
Type | Name | Description |
---|---|---|
Type | typeOfService | the type of the service to resolve |
Returns
Type | Description |
---|---|
object |
TryResolve<TService>()
try to resolve an instance for the given type from the dependency injection container. will return null if unresolvable.
Declaration
TService? TryResolve<TService>() where TService : class
Returns
Type | Description |
---|---|
TService |
Type Parameters
Name | Description |
---|---|
TService | the type of the service to resolve |