Building a Service Locator class
The core of any service locator class is the services in its care, so we’ll start by storing private references for each service and exposing public static methods for registering and retrieving those references from anywhere in our project. In the Scripts folder, create a new C# script named BasicLocator
and update its contents to match the following code block.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// 1
public class BasicLocator
{
// 2
private static ILogContract _logging;
private static ISaveContract _saving;
// 3
public static void RegisterLogger(ILogContract service)
{
_logging = service;
Debug.Log("Logging service registered...");
}
public static void RegisterSaver(ISaveContract service)
{
_saving = service;
Debug.Log("Saving service registered...");
}
// 4
public static ILogContract GetLogService...