Ijwu / PhoenixPointModLoader

Provides an interface for injecting code into the game Phoenix Point. Based on the BattleTech Mod Loader.
Apache License 2.0
3 stars 1 forks source link

Dependency Injection for Mods #2

Closed Ijwu closed 4 years ago

Ijwu commented 4 years ago

SimpleInjector is now used to provide DI for mods. Mods may request services provided by PPML by placing them as constructor parameters. PPML will attempt to resolve the dependencies and provide them to the mod during construction.

Recommended best practice is to store the injected services and only make use of them in the Initialize() function so as to prevent unintended behavior when constructing mods.

See the EnableConsoleAccess mod for an example.

Currently only one service is made available to mods, the IFileConfigProvider. This is implemented by the JsonFileConfigProvider as an easy way to read and dump configuration objects. JSON isn't necessarily the format I'm settling on permanently as it's not the most user friendly. However, it's developer-friendly and I'm trying to make some progress.