finalizing main menu + DI container
This commit is contained in:
1 parent
b465de1bf7
commit
b974bbd843
30 files changed
+1478
-399
No files matched your search
@@ -0,0 +1,18 @@
|
||||
using Code.Input;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Code.DI
|
||||
{
|
||||
public class Bootstrapper : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private InputActionAsset inputActionAsset;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
var container = new GameObject("DIContainer").AddComponent<DIContainer>();
|
||||
|
||||
container.Register<IInputService>(new InputService(inputActionAsset));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c0e2e6ddaf841588115d29a403122f9
|
||||
timeCreated: 1769496855
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.DI
|
||||
{
|
||||
public class DIContainer : MonoBehaviour
|
||||
{
|
||||
private readonly Dictionary<Type, object> _services = new();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
public void Register<T>(T service)
|
||||
{
|
||||
var type = typeof(T);
|
||||
if (!_services.TryAdd(type, service))
|
||||
{
|
||||
Debug.LogWarning($"Service {type} is already registered.");
|
||||
}
|
||||
}
|
||||
|
||||
public T Resolve<T>()
|
||||
{
|
||||
var type = typeof(T);
|
||||
if (_services.TryGetValue(type, out var service))
|
||||
{
|
||||
return (T)service;
|
||||
}
|
||||
throw new Exception($"Service {type} not found.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4cf9b443633a411ebfc48fe9b0f981b4
|
||||
timeCreated: 1769496780
|
||||
Reference in new issue
Block a user