|
| 1 | +# Service Framework |
| 2 | + |
| 3 | +The Service Framework package by the [Reality Collective](https://www.realityCollective.io). This package is an extensible service framework to build highly performant components for your Unity projects. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The Service framework provides a service repository for enabling background services to run efficiently in a Unity project, it features capabilities such as: |
| 8 | + |
| 9 | +- Platform specific operation - choose which platforms your service runs on. |
| 10 | +- Zero Latency from Unity operations - services are fully c# based with no Unity overhead. |
| 11 | +- Ability to host several sub-services (service modules) as part of a service, automatically maintained by a parent service and also platform aware. |
| 12 | +- Fully configurable with Scriptable profiles - Each service can host a configuration profile to change the behaviour of your service without changing code. |
| 13 | + |
| 14 | +## Requirements |
| 15 | + |
| 16 | +- [Unity 2021.3 or above](https://unity.com/) |
| 17 | +- [RealityCollective.Utilities](https://github.com/realitycollective/com.realitycollective.utilities) |
| 18 | + |
| 19 | +### OpenUPM |
| 20 | + |
| 21 | +The simplest way to getting started using the utilities package in your project is via OpenUPM. Visit [OpenUPM](https://openupm.com/docs/) to learn more about it. Once you have the OpenUPM CLI set up use the following command to add the package to your project: |
| 22 | + |
| 23 | +```text |
| 24 | + openupm add com.realitycollective.service-framework |
| 25 | +``` |
| 26 | + |
| 27 | +## Use cases |
| 28 | + |
| 29 | +The service framework has been the foundation behind such toolkit's as Microsoft's MRTK and open source projects like the XRTK and newly formed [Reality Toolkit](https://www.realitytoolkit.io/). These utilise the framework to enable such use cases as: |
| 30 | + |
| 31 | +- A platform independent input system - A single service able to route input data from multiple controllers on various platforms, each controller only activates on the platform it was designed for. |
| 32 | +- An Authentication service - Able to integrate with multiple authentication providers as needed through a single interface. |
| 33 | +- A networking service - Utilising multiple endpoints for Lobbys, communication routes and data sharing. |
| 34 | + |
| 35 | +The possibilities are almost endless. |
| 36 | + |
| 37 | +--- |
| 38 | + |
| 39 | +## Getting Started |
| 40 | + |
| 41 | +### 1. Creating a service |
| 42 | + |
| 43 | +A fully featured "Service Generator" is included with the Service Framework to get you quickly started, by simply giving a service a name and a namespace with which to run from, the generator will quickly create: |
| 44 | + |
| 45 | +- An interface to identify your service to the Service Framework (all services are identified by their parent interface) |
| 46 | +- A configuration profile - to customise to the needs of your service (optional, delete if not required) |
| 47 | +- The Service Implementation - You service to do with as you wish. |
| 48 | + |
| 49 | +Additionally, the generator can also create additional data providers (sub services) for your service to maintain, these require you to specify the parent services interface when generating to ensure they are appropriately bound in creation. Data Providers are automatically started with a parent service provided their platforms match the current operating environment. |
| 50 | + |
| 51 | +### 2. Configuring your service |
| 52 | + |
| 53 | +With your service created, it will need to be registered with an active "Service Manager" in a scene, this can either use the provided "Service Manager Instance" component on a GameObject, or uitilised as a private property on a class of your own. |
| 54 | + |
| 55 | +> Note, at this time, only a single Service Framework Manager can be active in the scene at a time. |
| 56 | +
|
| 57 | +Simply create an empty GameObject and add the **ServiceManagerInstance** component to it to begin. From there it is simply a matter of creating a Profile for the Service Manager and then adding your services to it. |
| 58 | + |
| 59 | +### 3. Accessing your running services |
| 60 | + |
| 61 | +Your services are available at any time from anywhere in your code by simply requesting the service from the Service Manager using its interface (Data Providers are also accessible directly, although we recommend working through your service), for example: |
| 62 | + |
| 63 | +```csharp |
| 64 | + var myService = ServiceManager.Instance.GetService<MyServiceInterface>(); |
| 65 | +``` |
| 66 | + |
| 67 | +Alternatively, there are also TryGet versions of the Service endpoints which return a bool to denote the service retrieval was successful and an out parameter to output the service instance, for example: |
| 68 | + |
| 69 | +```csharp |
| 70 | + IService myServiceInstance; |
| 71 | + if(!ServiceManager.Instance.TryGetService<MyServiceInterface>(out myServiceInstance)) |
| 72 | + { |
| 73 | + // Do something if your service was not found. |
| 74 | + } |
| 75 | +``` |
| 76 | + |
| 77 | +--- |
| 78 | + |
| 79 | +## Feedback |
| 80 | + |
| 81 | +Please feel free to provide feedback via the [Reality Toolkit dev channel here](https://github.com/realitycollective/com.realitycollective.service-framework/issues), all feedback. suggestions and fixes are welcome. |
| 82 | + |
| 83 | +--- |
| 84 | + |
| 85 | +## Related Articles |
| 86 | + |
| 87 | +- [Welcome to the Service Framework](https://service-framework.realitycollective.io/docs/get-started) |
| 88 | +- [Introduction](https://service-framework.realitycollective.io/docs/basics/introduction) |
| 89 | +- [Creating your first service](https://service-framework.realitycollective.io/docs/basics/getting_started) |
| 90 | +- [Roadmap](https://service-framework.realitycollective.io/docs/basics/roadmap) |
| 91 | + |
| 92 | +--- |
| 93 | + |
| 94 | +## Raise an Information Request |
| 95 | + |
| 96 | +If there is anything not mentioned in this document or you simply want to know more, raise an [RFI (Request for Information) request here](https://github.com/realitycollective/com.realitycollective.service-framework/issues/new?assignees=&labels=question&template=request_for_information.md). |
| 97 | + |
| 98 | +Or simply [**join us on Discord**](https://discord.gg/YjHAQD2XT8) and come chat about your questions, we would love to hear from you |
0 commit comments