-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support parameters in wire[] to override dependencies #7
Comments
+1 |
As a workaround, you can kind of trick Macwire to do this by making a factory then using it just once: lazy val sA = {
def make(config: Map[String, String]): Service = wire[Service]
make(Map("username" -> "admin"))
} |
That must be the first MacWire hack - nice ;) |
Since #11 is implemented you can also do this: lazy val sA = {
val config = Map("username" -> "admin")
wire[Service]
} The advantage over |
Can we add this method of solving ambiguity to the readme? In some cases it seems like a more practical approach than using Qualifiers |
@k0rn1 please do, PR will be great :) |
(One of the ideas from ScalaDays 2014 - by @matthewfarwell)
The
wire[]
method could accept parameters, which would be used to wire an instance of the given type; the parameters would take precedence over (override)val
s/def
s in wider scopes.Example usage:
A parameter which doesn't match any of the constructor parameters of the wired type would result in a compile-time error.
This can be useful for:
The text was updated successfully, but these errors were encountered: