Last active
December 23, 2015 00:09
-
-
Save hhariri/6551839 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
val appServer = AppServer() | |
appServer.resolveDependencies(ContainerConfiguration) // this is the IoC container configuration | |
appServer.get("/customers", { | |
with<Database> { | |
response.send(getCustomers()) // see below why this works | |
} | |
}) | |
appServer.start() | |
public trait Database { | |
fun getCustomers(): ArrayList<Customer> | |
} | |
public class SQLDatabase: Database { | |
fun getCustomers() { .... } | |
} | |
// IoC Config passed initially | |
container.map<Database>.to<SQLDatabase>.cacheBy(HttpRequest) // pseudo-code | |
/* | |
appServer.get is a function that takes a string and an extension method to RouteHandler class. RouteHandler has a property response. | |
That's why you can call response.send inside that lambda block. | |
Much the same way, with is also a function that takes as parameter a extension to the type it's using, so that's why in that block | |
you can call getCustomers(). with is implemented like so: | |
*/ | |
public fun with<T>(op: T.() -> Unit) where T: Any { | |
// delegate creation of the T instance to the registered IoC Container. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment