dependency-injection.net-6.0akka.net

Akka.DependencyInjection doesn't throw error when can't resolve dependencies


I'm using the DI in the following way:

 _actorSystem.ActorOf(
    Supervise(PropsWithDI<MessagePublisherActor>()), MessagePublisher.ActorName);

private Props PropsWithDI<T>(params object[] args) where T : ActorBase
    => DependencyResolver.For(_actorSystem).Props<T>(args);

If somehow there is a Constructor parameter which isn't added to the DI container, it simply doesn't create the Actor, which is normal of course but I would expect an error or something.

Am I using it wrong or is this a missing functionality of Akka.NET Akka.DependencyInjection.


Solution

  • Looks like indeed you can at least catch the error on runtime which helps a lot. I ended up with something similar:

    .WithSupervisorStrategy(new OneForOneStrategy(receivedException =>
                    {
                        _logger.LogError("Eror: {exception}", receivedException);
                        return Directive.Escalate;
                    }));
    

    This article has more information about how to set up the supervisior:

    https://getakka.net/articles/concepts/supervision.html

    var childProps = Props.Create<EchoActor>();
    
    var supervisor = BackoffSupervisor.Props(
        Backoff.OnStop(
            childProps,
            childName: "myEcho",
            minBackoff: TimeSpan.FromSeconds(3),
            maxBackoff: TimeSpan.FromSeconds(30),
            randomFactor: 0.2)
            .WithAutoReset(TimeSpan.FromSeconds(10))
            .WithSupervisorStrategy(new OneForOneStrategy(exception =>
            {
                if (exception is MyException)
                    return Directive.Restart;
                return Directive.Escalate;
            })));
    
    system.ActorOf(supervisor, "echoSupervisor");