Class ServiceProvider
Provides users with immediate access to the IServiceProvider bound to this ActorSystem, if any.
Implements
Inherited Members
Namespace: Akka.DependencyInjection
Assembly: Akka.DependencyInjection.dll
Syntax
[Obsolete("Replaced by the Akka.DependencyInjection.DependencyResolver in Akka.NET v1.4.21. Please switch to that.")]
public sealed class ServiceProvider : IExtension
Remarks
[OBSOLETE] Switch to the DependencyResolver instead.
Constructors
| Improve this Doc View SourceServiceProvider(IServiceProvider)
Declaration
public ServiceProvider(IServiceProvider provider)
Parameters
Type | Name | Description |
---|---|---|
IServiceProvider | provider |
Properties
| Improve this Doc View SourceProvider
The globally scoped IServiceProvider.
Declaration
public IServiceProvider Provider { get; }
Property Value
Type | Description |
---|---|
IServiceProvider |
Remarks
Per https://docs.microsoft.com/en-us/dotnet/core/extensions/dependency-injection-guidelines - please use the appropriate Microsoft.Extensions.DependencyInjection.IServiceScope for your actors and the dependencies they consume. DI is typically not used for long-lived, stateful objects such as actors.
Therefore, injecting transient dependencies via constructors is a bad idea in most cases. You'd be far better off creating a local "request scope" each time your actor processes a message that depends on a transient dependency, such as a database connection, and disposing that scope once the operation is complete.
Actors are not MVC Controllers. Actors can live forever, have the ability to restart, and are often stateful. Be mindful of this as you use this feature or bad things will happen. Akka.NET does not magically manage scopes for you.
Methods
| Improve this Doc View SourceFor(ActorSystem)
Declaration
public static ServiceProvider For(ActorSystem actorSystem)
Parameters
Type | Name | Description |
---|---|---|
ActorSystem | actorSystem |
Returns
Type | Description |
---|---|
ServiceProvider |
Props<T>(Object[])
Uses a delegate to dynamically instantiate an actor where some of the constructor arguments are populated via dependency injection and others are not.
Declaration
public Props Props<T>(params object[] args)
where T : ActorBase
Parameters
Type | Name | Description |
---|---|---|
Object[] | args | Optional. Any constructor arguments that will be passed into the actor's constructor directly without being resolved by DI first. |
Returns
Type | Description |
---|---|
Props | A new Props instance which uses DI internally. |
Type Parameters
Name | Description |
---|---|
T | The type of actor to instantiate. |
Remarks
YOU ARE RESPONSIBLE FOR MANAGING THE LIFECYCLE OF YOUR OWN DEPENDENCIES. AKKA.NET WILL NOT ATTEMPT TO DO IT FOR YOU.