This section is intended to provide an overview of the
SimApp
app_di.go
file with App Wiring.
app_config.go
The app_config.go
file is the single place to configure all modules parameters.
-
Create the
AppConfig
variable: simapp/app_config.goSee full example on GitHub Where theappConfig
combines the runtime configuration and the (extra) modules configuration. simapp/app_di.goSee full example on GitHub -
Configure the
runtime
module: In this configuration, the order at which the modules are defined in PreBlockers, BeginBlocks, and EndBlockers is important. They are named in the order they should be executed by the module manager. simapp/app_config.goSee full example on GitHub -
Wire the other modules:
Next to runtime, the other (depinject-enabled) modules are wired in the
AppConfig
: simapp/app_config.goSee full example on GitHub Note: thetx
isn’t a module, but a configuration. It should be wired in theAppConfig
as well. simapp/app_config.goSee full example on GitHub
app_config.go
file for SimApp
here.
Alternative formats
The example above shows how to create an
AppConfig
using Go. However, it is also possible to create an AppConfig
using YAML, or JSON. The configuration can then be embed with go:embed
and read with appconfig.LoadYAML
, or appconfig.LoadJSON
, in app_di.go
.app.yaml
can be found here.
app_di.go
app_di.go
is the place where SimApp
is constructed. depinject.Inject
automatically wires the app modules and keepers when provided with an application configuration (AppConfig
). SimApp
is constructed upon calling the injected *runtime.AppBuilder
with appBuilder.Build(...)
. In short depinject
and the runtime
package abstract the wiring of the app, and the AppBuilder
is the place where the app is constructed. runtime
takes care of registering the codecs, KV store, subspaces and instantiating baseapp
.
simapp/app_di.go
When using
depinject.Inject
, the injected types must be pointers.Advanced Configuration
In advanced cases, it is possible to inject extra (module) configuration in a way that is not (yet) supported byAppConfig
. In this case, use depinject.Configs
for combining the extra configuration, and AppConfig
and depinject.Supply
for providing the extra configuration. More information on how depinject.Configs
and depinject.Supply
function can be found in the depinject
documentation.
simapp/app_di.go
Registering non app wiring modules
It is possible to combine app wiring / depinject enabled modules with non-app wiring modules. To do so, use theapp.RegisterModules
method to register the modules on your app, as well as app.RegisterStores
for registering the extra stores needed.
When using AutoCLI and combining app wiring and non-app wiring modules. The AutoCLI options should be manually constructed instead of injected. Otherwise it will miss the non depinject modules and not register their CLI.
Complete app_di.go
Note that in the complete
SimApp
app_di.go
file, testing utilities are also defined, but they could as well be defined in a separate file.