afIocEnv is a small utility library for afIoc that scans system information to determine what environment your application is running in. It looks at environment variables, program arguments and even offers a manual override option.
using afIoc
using afIocConfig
using afIocEnv
class Example {
@Inject IocEnv iocEnv // --> Inject IocEnv service
@Config { id="afIocEnv.isProd" } // --> Inject Config values
@Inject Bool isProd
new make(|This| in) { in(this) }
Void wotever() {
echo("The environment is '${iocEnv.env}'")
if (isProd) {
echo("I'm in Production!")
} else {
echo("I'm in Development!!")
}
}
}
// ---- Standard afIoc Support Classes ----
class Main {
Void main() {
registry := RegistryBuilder().addModules([AppModule#, IocEnvModule#, IocConfigModule#]).build.startup
example := (Example) registry.dependencyByType(Example#)
example.wotever()
}
}
class AppModule {
static Void bind(ServiceBinder binder) {
binder.bindImpl(Example#)
}
}
Run Example.fan from the command line:
C:\> fan Example.fan -env PRODUCTION
[info] [afIocEnv] Setting from environment variable 'env' : development
[info] [afIocEnv] Overriding from cmd line argument '-env' : PRODUCTION
The environment is 'PRODUCTION'
I'm in Production!
SlimerDude Tue 3 Dec 2013
afIocEnv v1.0.0
afIocEnv
is a small utility library for afIoc that scans system information to determine what environment your application is running in. It looks at environment variables, program arguments and even offers a manual override option.fanr install -r http://repo.status302.com/fanr/ afIocEnv
Quick Start
Example.fan:
Run Example.fan from the command line:
Read more in the Fantom-Factory article Dev, Test or Prod; What is Your Machine?.