Feature Request: Factory Methods for Akka Actors

Open
#128 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
scala
Domain
backend

Research direction

Start by reading the existing wireWith functionality and the wireActorWith entry point in the Akka support API. Compare the proposed currying or factory-function approaches, then define a supported way to wire an actor with supplied constructor arguments and validate it against the UserFinderActor example.

Written by the indexing model from the issue text.

Description

If we want to use an alternative constructor for a regular class, we can use the wireWith function to select the factory that we want. It would be nice to have this functionality for akka actors as well, either via currying / partial application or factory functions.

For example:

import akka.actor.{Actor, ActorRef, ActorSystem}

class DatabaseAccess()
class UserFinderActor(configArg: Int, databaseAccess: DatabaseAccess) extends Actor {
  override def receive: Receive = {
    case m => // ...
  }
}
object UserFinderActor {
  def apply(configArg: Int)(databaseAccess: DatabaseAccess) = new UserFinderActor(configArg,databaseAccess) 
}

import com.softwaremill.macwire._
import com.softwaremill.macwire.akkasupport._
  
val theDatabaseAccess = wire[DatabaseAccess]
					     
val system = ActorSystem("actor-system")

val theUserFinder = wireActorWith(UserFinderActor(1) _)("userFinder")  
Dominant language
Scala
Stars
1.3k
Forks
77
Avg merge
9m
Merged PRs (30d)
4

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from softwaremill/macwire

All issues in softwaremill/macwire

Similar issues

More Scala issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.