0
votes

I want to make a library that is going to be used and configurable by other people, using akka actors.

I want to make a Repository actor to which a type of storage will be injected by the library user like "MemoryDatabase" or "FileDatabase" or anything that extends a defined class or actor (see question 2).

1) What is the best way for a user to specify options (including his own created ones)?

2) Should "MemoryDatabase" be an actor child of repository, or just a normal class as a field/property of the Repository actor in this case?

Thanks!

-Jojolepro

Edit: I want to make an actor that looks like

class Repository extends Actor{

 val repoType:DataStorageType = ...

 def receive:Receive={}

}

What I want to know the best way for a end user of such library to specify the repoType field, considering that Repository is already in a predefined actor hierarchy.

1
Well... the question is too open ended and there should be at least 100 equally nice ways to do it depending on various other factors. I am sorry to inform you that unless you provide a more concrete question statement, most of us will be unable to help you in this. - sarveshseri
Edited my question to be more specific - joel lupien

1 Answers

0
votes

It depends on if you want the user to put in a concrete instance or merely a type. Ignoring any kind of DI system you could use, I would merely pass the concrete instance to the actor's constructor via props when the actor is started but then that would depend on the concrete instance being thread safe because not necessarily only that actor would be managing it. If you want the actor to own the repository, have the user pass the factory instance or type to the props and thus the constructor.