tysonnorris commented on a change in pull request #2414: SPI approach for
pluggable implementations
URL:
https://github.com/apache/incubator-openwhisk/pull/2414#discussion_r130931297
##########
File path: docs/spi.md
##########
@@ -0,0 +1,89 @@
+# SPI extensions in OpenWhisk
+
+Alternate implementations of various components follow an SPI (Service
Provider Interface) pattern:
+* The pluggable component is defined as an Spi trait:
+```scala
+import whisk.spi.Spi
+trait ThisIsPluggable extends Spi { ... }
+```
+* Implementations implement the Spi trait
+```scala
+class TheImpl extends ThisIsPluggable { ... }
+class TheOtherImpl extends ThisIsPluggable { ... }
+```
+
+Runtime resolution of an Spi trait to a specific impl is provided by:
+* Akka Extensions - a service registry housed inside the ActorSystem
+* SpiModule - a way to define a factory for each impl, all of which are loaded
via ServiceLoader
+* application.conf - each SpiModule defines a config key used to indicate
which impl should be used at runtime
+
+# Example
+
+The process to create and use an SPI is as follows:
+
+## Define the Spi and impl(s)
+
+* create your Spi trait `YourSpi` as an extension of whisk.spi.Spi
+* create your impls as classes that extend `YourSpi`
+
+## Define the SpiModule(s) to load the impl(s)
+
+```scala
+class YourImplModule extends SpiModule[YourSpi]{
+ def getInstance = new YourImpl
+}
+```
+
+To use scaldi injectors to bind dependencies, use:
+```scala
+class YourImplModule extends SpiFactoryModule[YourSpi]{
+ def getInstance(implicit injector:Injector) = new
YourImpl(inject[SomeDependencyType])
+}
+```
+
+Note: To bind dependencies (must be done before first access of the Spi):
+```scala
+//bind config
+SharedModules.bind[WhiskConfig](whiskConfig)
+//bind an Spi instance
+SharedModules.bind[YourSpi](yourSpi)
Review comment:
yep, done
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services