since a few weeks I play with Sindi 0.5 (IoC Container) in my Scala (2.9.1) project. 99% are fine but often I need new instances of a class with user input. In the Sindi User Guide all constructor parameters are injected as static values and I didn't found other tutorials of Sindi. So I test the following example code:
import sindi._
trait Digits {
val dig1: Int
val dig2: Double
}
class MyDigits(override val dig1: Int, override val dig2: Double) extends Digits {
override def toString = super.toString + "\ndigit 1: " + dig1 + "\ndigit 2: " + dig2
}
//DigitModule ist Sindi specific.
final class DigitModule(override val ctx: Context) extends Module {
override val bindings = Bindings(
bind[Digits] to provider(new MyDigits(digit1, digit2))
)
private var digit1: Int = _
private var digit2: Double = _
def digits(d1: Int, d2: Double) : Digits = {
digit1 = d1
digit2 = d2
inject[Digits]
}
}
This DigitModule works. The method digits() can be called from another Context (also Sindi specific) with values from a user. But is this the best solution? The method writes the parameter values into the private vars and then the inject[Digits] command creates/inject a new MyDigit class with the values of the private vars. I think this indirection is a poor way and I hope of a solution like inject[Digits](Int, Double) or something like this. A solution without indirection wouldn't go amiss.
Thank you
Olaf