Initializers are plain Julia files which are loaded early in the application cycle (before routes, controller, or models). They are designed to expose configuration code which might be needed later on in the application life cycle.
Initializers should be placed within the
config/initializers/ folder and they will be automatically loaded (included) by Genie.
If your configuration is environment dependent (ie a database connection which is different between dev and prod), it should be added to the corresponding
The initializers are loaded in the order they are read from the file system. If you have initializers which depend on other initializers, this is most likely a sign that you need to refactor using a model or a library file.
Library files are Julia files which provide distinct functionality and can be placed in the
lib/ folder where they are also automatically loaded by Genie. If the
lib/ folder does not exist, you can create it yourself.
All the definitions (variables, constants, functions, modules, etc) added to initializer files are loaded into your app’s module. So if your app is called
MyGenieApp, the definitions will be available under the
Given that your app’s name is variable, you can also access your app’s module through the
UserApp constant. So all the definitions added to initializers can also be accessed through the
UserApp module (
UserApp === MyGenieApp).
This is Genie’s default initializer for loading the SearchLight ORM. Please notice that the initializers does contain database configuration information, which is defined in a dedicated, environment dependent file. The initializer simply delegates the configuration loading and setup to the SearchLight package.
using SearchLight, SearchLight.QueryBuilder SearchLight.Configuration.load() if SearchLight.config.db_config_settings["adapter"] !== nothing SearchLight.Database.setup_adapter() SearchLight.Database.connect() SearchLight.load_resources() end