4

How does one build loose coupling to akka.net? Assume I have an MVC application that uses Akka.net and that I want to be able to test the controllers in the MVC app without using a real actor system. Kind of like when you want to test a business layer using a moq implementation of a data access repository. Normally in that case you define an intervace for the repository and you could test without a concrete repository.

In this case, I want to test my MVC app without using an actual actor system. This might be especially relevant if the MVC app interacts with a remote actor system. In this case I would like some kind of interface to represent the access to the remote actor system and actor.

cfcal
  • 161
  • 6

2 Answers2

3

ActorSystem implements IActorRefFactory

public interface IActorRefFactory
{
    IActorRef ActorOf(Props props, string name = null);
    ActorSelection ActorSelection(ActorPath actorPath);
    ActorSelection ActorSelection(string actorPath);
}

This should allow you to use your mocking framework of choice, mock an ActorSystem and have that return mock IActorRefs for your controllers to interact with.

Patrick Allwood
  • 1,822
  • 17
  • 21
0

This article broutght me much clarity how to build a bridge between the world of actor references and object references:

https://havret.io/akka-net-asp-net-core.

If briefly, you cannot pass Akka-world actor references via your DI framework, but what you can do is pass (to the constructor of the parent actor) delegates that will create the child actors and return their actor references. You can configure these delegates in your startup class where you have IServiceProvider that will be used for resolving the dependencies inside each delegate.

Oleg
  • 1,291
  • 13
  • 16