Search Results for

    Show / Hide Table of Contents

    Class ServiceProvider

    Provides users with immediate access to the IServiceProvider bound to this ActorSystem, if any.

    Inheritance
    object
    ServiceProvider
    Implements
    IExtension
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.ReferenceEquals(object, object)
    object.ToString()
    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

    | Edit this page View Source

    ServiceProvider(IServiceProvider)

    Declaration
    public ServiceProvider(IServiceProvider provider)
    Parameters
    Type Name Description
    IServiceProvider provider

    Properties

    | Edit this page View Source

    Provider

    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 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

    | Edit this page View Source

    For(ActorSystem)

    Declaration
    public static ServiceProvider For(ActorSystem actorSystem)
    Parameters
    Type Name Description
    ActorSystem actorSystem
    Returns
    Type Description
    ServiceProvider
    | Edit this page View Source

    Props<T>(params 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.

    Implements

    IExtension

    Extension Methods

    ObjectExtensions.IsDefaultForType<T>(T)
    ObjectExtensions.AsOption<T>(T)
    Extensions.AsInstanceOf<T>(object)
    In this article
    • githubEdit this page
    • View Source
    Back to top
    Contribute
    • Project Chat
    • Discussion Forum
    • Source Code
    Support
    • Akka.NET Support Plans
    • Akka.NET Observability Tools
    • Akka.NET Training & Consulting
    Maintained By
    • Petabridge - The Akka.NET Company
    • Learn Akka.NET