Simple service pattern plugin for Flax Engine, inspired by MonoGame ServiceContainer.
To incorportate the plugin to your flax project, simply add the two cs files (IServicePlugin.cs and ServicePlugin.cs ) anywhere in your project, or simply copy paste the code directly in new created cs files in your source project.
First you need to register a service, it can be done from anywhere you want as long you are registering a class, can also register an object by interface:
using FService;
ServicePlugin.Instance.AddService<MyServiceType>(MyServiceObject);
Then to retrieve a service simply call:
ServicePlugin.Instance.GetService<MyServiceType>();
You can also remove services (usefull for script type to be cleared on OnDestroy):
ServicePlugin.Instance.RemoveService(typeof(MyServiceType));
There are also two event Action callbacks you can subscribe to in the plugin for when a service is added and removed:
ServicePlugin.Instance.Add += MyVoidMethod;
ServicePlugin.Instance.Remove += MyVoidMethod;
This is pretty much the ServiceContainer from MonoGame project, just wrapped up for Flax Engine use.