This repository has been archived by the owner on Apr 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow parameterless components to be used. fixes #124
- Loading branch information
1 parent
1001284
commit 4a93c0e
Showing
3 changed files
with
72 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
tests/src/test/scala/org/zalando/grafter/ParameterlessComponentSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.zalando.grafter.macros | ||
|
||
|
||
/** | ||
* This is a compilation test to check that a component without parameters | ||
* can still be injected. see #124 | ||
*/ | ||
object ParameterlessComponentSpec { | ||
@readers | ||
case class ApplicationConfiguration(httpConfig: HttpConfig, additionalConfig: AdditionalConfig) | ||
|
||
/** | ||
* For a nested configuration you need to annotate the nested elements with the @readers annotation | ||
* as well | ||
*/ | ||
@readers | ||
case class HttpConfig(cfg1: HttpSubConfig1, cfg2: HttpSubConfig2) | ||
|
||
case class HttpSubConfig1(port: Int) | ||
case class HttpSubConfig2(host: String) | ||
case class AdditionalConfig(config3: String) | ||
|
||
@reader | ||
case class HttpClient(config: HttpSubConfig2) | ||
|
||
|
||
@reader | ||
case class SomeService(client: HttpClient) | ||
|
||
@reader | ||
case class SomeServiceWithoutParameters() | ||
|
||
@reader | ||
case class WebApplication(someService: SomeService, emptyService: SomeServiceWithoutParameters) | ||
|
||
|
||
object MyApp extends App { | ||
|
||
val config = ApplicationConfiguration( | ||
HttpConfig(HttpSubConfig1(80), HttpSubConfig2("bla")), | ||
AdditionalConfig("3") | ||
) | ||
|
||
val app = WebApplication.reader[ApplicationConfiguration].apply(config) | ||
|
||
} | ||
} | ||
|