-
Notifications
You must be signed in to change notification settings - Fork 0
Usage.Service Container
Namespace: Ju.Services
The Service Container is the dependency injection container of this framework, it will help to achieve decoupling in your project.
There is no automatic injection anywhere in the code (you can implement your own though).
void RegisterService<T>() where T : IService;
void RegisterService<T1, T2>() where T2 : T1, IService;
void RegisterLazyService<T>() where T : IService;
void RegisterLazyService<T1, T2>() where T2 : T1, IService;
void RegisterFactory<T>(Func<T> classConstructor);
T Get<T>();
void UnloadService<T>() where T : IService;
Register a service. The service must implement the empty interface IService.
It will be loaded right away when you get any service for the first time.
You can register a service T2 but as the type T1 (T2 must inherit or implement T1) so you can use interfaces or abstract services. For example:
// This will register TaskService using ITaskService as a type
ServiceContainer.RegisterService<ITaskService, TaskService>();
// Get the TaskService but using the interface ITaskService
ServiceContainer.Get<ITaskService>();
// Same but using the syntactic sugar (See Getting Started page for your platform)
Core.Get<ITaskService>();
// Same, but shorter
Core.Task
This works the same as the previous method but the service won't load until you get it for the first time using Get
.
Register a constructor function in order to set up a factory of objects. You can use any type you want.
This method will return a service reference or constructs a new object if it was registered as a factory.
Unloads a service so it won't be available anymore.
Additionally, you can register multiple services or factories of the same type if you give them a string ID.
void RegisterService<T>(string id) where T : IService;
void RegisterService<T1, T2>(string id) where T2 : T1, IService;
void RegisterLazyService<T>(string id) where T : IService;
void RegisterLazyService<T1, T2>(string id) where T2 : T1, IService;
void RegisterFactory<T>(string id, Func<T> classConstructor);
T Get<T>(string id);
void UnloadService<T>(string id) where T : IService;
Return to [Home]
- Home
- Install
- Manual
-
Core API
- Services:
- Util:
-
Unity API
- Services:
- Integrations: