Skip to content

Service Injector

This package provides a simple way to inject configs into ECS for your modules to take from.

Usage

The package provides a ConfigBootstrapHelper class that is a monobehaviour instance thus depends on a Gameobject for its usage. In the inspector you can add your configs in the form of ECS singletons that will be injected into the world provided.

There are two ways you can bootstrap your configuration into ECS. - One is the same familiar way that one would work with ECS components but a class or struct must inherit IConfigSingleton. - The other is if you want to inject directly a ScriptableObject, then you can do so by inheriting ScriptableConfigSingleton.

As an example you could have a Managed Singleton (IManagedSingletonService) that takes a ScriptableObject as a value and one of the later modules could use the GetSingleton<>() call to request it.

Example of a Config Singleton:

public partial class ExampleManagedSingleton : IConfigSingleton {
    // This could be any asset like a ScriptableObject
    public ExampleConfig Value;
}

public partial struct ExampleSingleton : IConfigSingleton {
    public FixedString64Bytes Name;
}

Or for a ScriptableObject:

[CreateAssetMenu(fileName = "ExampleConfig", menuName = "Stratkit/Service Injector Sample/ExampleConfig")]
public partial class ConfigObject : ScriptableConfigSingleton {
    public string Name;
    public int Age;
}

Inspector Editor

ExampleInspector.png