From bd153677aec54d693e73f8b46c20e4b8e1463a50 Mon Sep 17 00:00:00 2001 From: Oleg Pulkin Date: Mon, 25 Mar 2024 20:16:16 +0300 Subject: [PATCH 01/11] upd ServiceLocator --- Code/Runtime/OlegHcp/Managing/Interfaces.cs | 9 -- .../OlegHcp/Managing/Interfaces.cs.meta | 11 -- .../OlegHcp/Managing/ServiceLocator.cs | 79 +++++++++----- .../OlegHcp/Managing/ServiceLocatorDirty.cs | 52 +++++++++ ...on.cs.meta => ServiceLocatorDirty.cs.meta} | 2 +- .../OlegHcp/Managing/ServiceLocatorLazy.cs | 101 ------------------ .../Managing/ServiceLocatorLazy.cs.meta | 11 -- .../Managing/ServiceNotFoundException.cs | 13 --- 8 files changed, 108 insertions(+), 170 deletions(-) delete mode 100644 Code/Runtime/OlegHcp/Managing/Interfaces.cs delete mode 100644 Code/Runtime/OlegHcp/Managing/Interfaces.cs.meta create mode 100644 Code/Runtime/OlegHcp/Managing/ServiceLocatorDirty.cs rename Code/Runtime/OlegHcp/Managing/{ServiceNotFoundException.cs.meta => ServiceLocatorDirty.cs.meta} (83%) delete mode 100644 Code/Runtime/OlegHcp/Managing/ServiceLocatorLazy.cs delete mode 100644 Code/Runtime/OlegHcp/Managing/ServiceLocatorLazy.cs.meta delete mode 100644 Code/Runtime/OlegHcp/Managing/ServiceNotFoundException.cs diff --git a/Code/Runtime/OlegHcp/Managing/Interfaces.cs b/Code/Runtime/OlegHcp/Managing/Interfaces.cs deleted file mode 100644 index bb4a7b91..00000000 --- a/Code/Runtime/OlegHcp/Managing/Interfaces.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace OlegHcp.Managing -{ - public interface IService { } - - public interface IObjectFactory where T : class, IService - { - T Create(); - } -} diff --git a/Code/Runtime/OlegHcp/Managing/Interfaces.cs.meta b/Code/Runtime/OlegHcp/Managing/Interfaces.cs.meta deleted file mode 100644 index 21ad0fdb..00000000 --- a/Code/Runtime/OlegHcp/Managing/Interfaces.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: de8dfc8db64913f4989df4544210d684 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs b/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs index 0f4c8433..a80845c9 100644 --- a/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs +++ b/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using OlegHcp.Tools; +using System.Runtime.Serialization; + #if !UNITY_2021_2_OR_NEWER using OlegHcp.CSharp.Collections; @@ -8,14 +10,21 @@ namespace OlegHcp.Managing { + public interface IService { } + + public interface IInitialContext where T : class, IService + { + T GetOrCreateInstance(); + } + public class ServiceLocator { - private Dictionary _storage = new Dictionary(); + private protected Dictionary _storage = new Dictionary(); public T Get(bool error = true) where T : class, IService { - if (_storage.TryGetValue(typeof(T), out IService value)) - return (T)value; + if (_storage.TryGetValue(typeof(T), out Data value)) + return (T)value.Service; if (error) throw ThrowErrors.ServiceNotRegistered(typeof(T)); @@ -23,46 +32,68 @@ public T Get(bool error = true) where T : class, IService return null; } - public void Register(T service, bool error = true) where T : class, IService + public void Register(IInitialContext context, bool error = true) where T : class, IService { - if (service == null) - throw ThrowErrors.NullParameter(nameof(service)); + if (context == null) + throw ThrowErrors.NullParameter(nameof(context)); - if (_storage.TryAdd(typeof(T), service)) + if (_storage.TryAdd(typeof(T), new Data(context))) return; if (error) - throw new InvalidOperationException($"Service {typeof(T).Name} already registered."); + throw new InvalidOperationException($"Service {typeof(T)} already registered."); } - public bool Unregister(bool dispose = true) where T : class, IService + public void Register(Func instanceProvider, bool error = true) where T : class, IService { - if (!dispose) - return _storage.Remove(typeof(T)); + if (instanceProvider == null) + throw ThrowErrors.NullParameter(nameof(instanceProvider)); + + Register(new DefaultInitialContext(instanceProvider), error); + } + + private protected class Data + { + private IService _service; + private IInitialContext _context; + + public IService Service => _service ?? (_service = _context.GetOrCreateInstance()); - if (_storage.Remove(typeof(T), out IService value)) + public Data(IInitialContext context) { - if (value is IDisposable disposable) + _context = context; + } + + public void Clear(bool dispose) + { + if (dispose && _service is IDisposable disposable) disposable.Dispose(); - return true; + _service = null; } - - return false; } - public void UnregisterAll(bool dispose = true) + private class DefaultInitialContext : IInitialContext where T : class, IService { - if (dispose) + private Func _provider; + + public DefaultInitialContext(Func provider) { - foreach (var value in _storage.Values) - { - if (value is IDisposable disposable) - disposable.Dispose(); - } + _provider = provider; } - _storage.Clear(); + T IInitialContext.GetOrCreateInstance() + { + return _provider.Invoke(); + } } } + + public class ServiceNotFoundException : Exception + { + public ServiceNotFoundException() : base() { } + public ServiceNotFoundException(string message) : base(message) { } + public ServiceNotFoundException(string message, Exception innerException) : base(message, innerException) { } + public ServiceNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { } + } } diff --git a/Code/Runtime/OlegHcp/Managing/ServiceLocatorDirty.cs b/Code/Runtime/OlegHcp/Managing/ServiceLocatorDirty.cs new file mode 100644 index 00000000..3015903b --- /dev/null +++ b/Code/Runtime/OlegHcp/Managing/ServiceLocatorDirty.cs @@ -0,0 +1,52 @@ +#if !UNITY_2021_2_OR_NEWER +using OlegHcp.CSharp.Collections; +#endif + +namespace OlegHcp.Managing +{ + public class ServiceLocatorDirty : ServiceLocator + { + public bool RemoveInstance(bool dispose = true) where T : class, IService + { + if (_storage.TryGetValue(typeof(T), out Data value)) + { + value.Clear(dispose); + return true; + } + + return false; + } + + public void ClearInstances(bool dispose = true) + { + foreach (Data item in _storage.Values) + { + item.Clear(dispose); + } + } + + public bool Unregister(bool dispose = true) where T : class, IService + { + if (_storage.Remove(typeof(T), out Data value)) + { + value.Clear(dispose); + return true; + } + + return false; + } + + public void UnregisterAll(bool dispose = true) + { + if (dispose) + { + foreach (Data value in _storage.Values) + { + value.Clear(true); + } + } + + _storage.Clear(); + } + } +} diff --git a/Code/Runtime/OlegHcp/Managing/ServiceNotFoundException.cs.meta b/Code/Runtime/OlegHcp/Managing/ServiceLocatorDirty.cs.meta similarity index 83% rename from Code/Runtime/OlegHcp/Managing/ServiceNotFoundException.cs.meta rename to Code/Runtime/OlegHcp/Managing/ServiceLocatorDirty.cs.meta index 1b191c7e..e136a94b 100644 --- a/Code/Runtime/OlegHcp/Managing/ServiceNotFoundException.cs.meta +++ b/Code/Runtime/OlegHcp/Managing/ServiceLocatorDirty.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f5982ea878712fe4eb0e20ab024f9888 +guid: 4ad3e660498150449a5b6353828af925 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Code/Runtime/OlegHcp/Managing/ServiceLocatorLazy.cs b/Code/Runtime/OlegHcp/Managing/ServiceLocatorLazy.cs deleted file mode 100644 index e03f4321..00000000 --- a/Code/Runtime/OlegHcp/Managing/ServiceLocatorLazy.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System; -using System.Collections.Generic; -using OlegHcp.Tools; - -#if !UNITY_2021_2_OR_NEWER -using OlegHcp.CSharp.Collections; -#endif - -namespace OlegHcp.Managing -{ - public class ServiceLocatorLazy - { - private Dictionary _storage = new Dictionary(); - - public T Get(bool error = true) where T : class, IService - { - if (_storage.TryGetValue(typeof(T), out Data value)) - return (T)value.Service; - - if (error) - throw ThrowErrors.ServiceNotRegistered(typeof(T)); - - return null; - } - - public void Register(IObjectFactory factory, bool error = true) where T : class, IService - { - if (factory == null) - throw ThrowErrors.NullParameter(nameof(factory)); - - if (_storage.TryAdd(typeof(T), new Data(factory))) - return; - - if (error) - throw new InvalidOperationException($"Service {typeof(T)} already registered."); - } - - public void Register(Func creator, bool error = true) where T : class, IService - { - if (creator == null) - throw ThrowErrors.NullParameter(nameof(creator)); - - Register(new DefaultFactory(creator), error); - } - - public bool RemoveInstance(bool dispose = true) where T : class, IService - { - if (_storage.Remove(typeof(T), out Data value)) - { - value.Clear(dispose); - return true; - } - - return false; - } - - public void ClearInstances(bool dispose = true) - { - foreach (Data item in _storage.Values) - { - item.Clear(dispose); - } - } - - private class Data - { - private IService _service; - private IObjectFactory _factory; - - public IService Service => _service ?? (_service = _factory.Create()); - - public Data(IObjectFactory factory) - { - _factory = factory; - } - - public void Clear(bool dispose) - { - if (dispose && _service is IDisposable disposable) - disposable.Dispose(); - - _service = null; - } - } - - private class DefaultFactory : IObjectFactory where T : class, IService - { - private Func _create; - - public DefaultFactory(Func creator) - { - _create = creator; - } - - T IObjectFactory.Create() - { - return _create.Invoke(); - } - } - } -} diff --git a/Code/Runtime/OlegHcp/Managing/ServiceLocatorLazy.cs.meta b/Code/Runtime/OlegHcp/Managing/ServiceLocatorLazy.cs.meta deleted file mode 100644 index 3ef094df..00000000 --- a/Code/Runtime/OlegHcp/Managing/ServiceLocatorLazy.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: f43d74dd67b1d9744b35a728eb90217a -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Code/Runtime/OlegHcp/Managing/ServiceNotFoundException.cs b/Code/Runtime/OlegHcp/Managing/ServiceNotFoundException.cs deleted file mode 100644 index 1d48384b..00000000 --- a/Code/Runtime/OlegHcp/Managing/ServiceNotFoundException.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace OlegHcp.Managing -{ - public class ServiceNotFoundException : Exception - { - public ServiceNotFoundException() : base() { } - public ServiceNotFoundException(string message) : base(message) { } - public ServiceNotFoundException(string message, Exception innerException) : base(message, innerException) { } - public ServiceNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { } - } -} From 1cedddc8683d5a11c539370cef383089a825a49a Mon Sep 17 00:00:00 2001 From: Oleg Pulkin Date: Mon, 25 Mar 2024 20:34:53 +0300 Subject: [PATCH 02/11] upd ServiceLocator --- .../OlegHcp/Managing/BoldServiceLocator.cs | 24 ++++++++ ...rty.cs.meta => BoldServiceLocator.cs.meta} | 2 +- .../OlegHcp/Managing/DirtyServiceLocator.cs | 33 +++++++++++ .../Managing/DirtyServiceLocator.cs.meta | 11 ++++ .../OlegHcp/Managing/InitialContextData.cs | 25 +++++++++ .../Managing/InitialContextData.cs.meta | 11 ++++ .../OlegHcp/Managing/ServiceLocator.cs | 56 +++++++------------ .../OlegHcp/Managing/ServiceLocatorDirty.cs | 52 ----------------- 8 files changed, 125 insertions(+), 89 deletions(-) create mode 100644 Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs rename Code/Runtime/OlegHcp/Managing/{ServiceLocatorDirty.cs.meta => BoldServiceLocator.cs.meta} (83%) create mode 100644 Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs create mode 100644 Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs.meta create mode 100644 Code/Runtime/OlegHcp/Managing/InitialContextData.cs create mode 100644 Code/Runtime/OlegHcp/Managing/InitialContextData.cs.meta delete mode 100644 Code/Runtime/OlegHcp/Managing/ServiceLocatorDirty.cs diff --git a/Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs b/Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs new file mode 100644 index 00000000..f8e13239 --- /dev/null +++ b/Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs @@ -0,0 +1,24 @@ +namespace OlegHcp.Managing +{ + public class BoldServiceLocator : ServiceLocator + { + public bool RemoveInstance(bool dispose = true) where TService : class, IService + { + if (_storage.TryGetValue(typeof(TService), out InitialContextData value)) + { + value.ClearInstance(dispose); + return true; + } + + return false; + } + + public void RemoveAllInstances(bool dispose = true) + { + foreach (InitialContextData item in _storage.Values) + { + item.ClearInstance(dispose); + } + } + } +} diff --git a/Code/Runtime/OlegHcp/Managing/ServiceLocatorDirty.cs.meta b/Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs.meta similarity index 83% rename from Code/Runtime/OlegHcp/Managing/ServiceLocatorDirty.cs.meta rename to Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs.meta index e136a94b..c803629b 100644 --- a/Code/Runtime/OlegHcp/Managing/ServiceLocatorDirty.cs.meta +++ b/Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4ad3e660498150449a5b6353828af925 +guid: fdbb5c767581fce479cf732563e3ce19 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs b/Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs new file mode 100644 index 00000000..a24912b0 --- /dev/null +++ b/Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs @@ -0,0 +1,33 @@ +#if !UNITY_2021_2_OR_NEWER +using OlegHcp.CSharp.Collections; +#endif + +namespace OlegHcp.Managing +{ + public class DirtyServiceLocator : BoldServiceLocator + { + public bool Remove(bool dispose = true) where TService : class, IService + { + if (_storage.Remove(typeof(TService), out InitialContextData value)) + { + value.ClearInstance(dispose); + return true; + } + + return false; + } + + public void RemoveAll(bool dispose = true) + { + if (dispose) + { + foreach (InitialContextData value in _storage.Values) + { + value.ClearInstance(true); + } + } + + _storage.Clear(); + } + } +} diff --git a/Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs.meta b/Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs.meta new file mode 100644 index 00000000..cce17067 --- /dev/null +++ b/Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2e4c0aff78e0ace4d8a94640c5d10a7d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Code/Runtime/OlegHcp/Managing/InitialContextData.cs b/Code/Runtime/OlegHcp/Managing/InitialContextData.cs new file mode 100644 index 00000000..72b96f62 --- /dev/null +++ b/Code/Runtime/OlegHcp/Managing/InitialContextData.cs @@ -0,0 +1,25 @@ +using System; + +namespace OlegHcp.Managing +{ + internal class InitialContextData + { + private IInitialContext _context; + private IService _service; + + public IService Service => _service ?? (_service = _context.GetOrCreateInstance()); + + public InitialContextData(IInitialContext context) + { + _context = context; + } + + public void ClearInstance(bool dispose) + { + if (dispose && _service is IDisposable disposable) + disposable.Dispose(); + + _service = null; + } + } +} diff --git a/Code/Runtime/OlegHcp/Managing/InitialContextData.cs.meta b/Code/Runtime/OlegHcp/Managing/InitialContextData.cs.meta new file mode 100644 index 00000000..1cb6c7e2 --- /dev/null +++ b/Code/Runtime/OlegHcp/Managing/InitialContextData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 20cf25635a25e854fa0fc250ad6ac6a4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs b/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs index a80845c9..9d1fb66e 100644 --- a/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs +++ b/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs @@ -12,77 +12,61 @@ namespace OlegHcp.Managing { public interface IService { } - public interface IInitialContext where T : class, IService + public interface IInitialContext where TService : class, IService { - T GetOrCreateInstance(); + TService GetOrCreateInstance(); } public class ServiceLocator { - private protected Dictionary _storage = new Dictionary(); + private protected Dictionary _storage = new Dictionary(); - public T Get(bool error = true) where T : class, IService + public TService Get(bool error = true) where TService : class, IService { - if (_storage.TryGetValue(typeof(T), out Data value)) - return (T)value.Service; + if (_storage.TryGetValue(typeof(TService), out InitialContextData value)) + return (TService)value.Service; if (error) - throw ThrowErrors.ServiceNotRegistered(typeof(T)); + throw ThrowErrors.ServiceNotRegistered(typeof(TService)); return null; } - public void Register(IInitialContext context, bool error = true) where T : class, IService + public void Add(IInitialContext context, bool error = true) where TService : class, IService { if (context == null) throw ThrowErrors.NullParameter(nameof(context)); - if (_storage.TryAdd(typeof(T), new Data(context))) - return; - - if (error) - throw new InvalidOperationException($"Service {typeof(T)} already registered."); + AddInternal(context, error); } - public void Register(Func instanceProvider, bool error = true) where T : class, IService + public void Add(Func instanceProvider, bool error = true) where TService : class, IService { if (instanceProvider == null) throw ThrowErrors.NullParameter(nameof(instanceProvider)); - Register(new DefaultInitialContext(instanceProvider), error); + AddInternal(new DefaultInitialContext(instanceProvider), error); } - private protected class Data + private void AddInternal(IInitialContext context, bool error) where TService : class, IService { - private IService _service; - private IInitialContext _context; - - public IService Service => _service ?? (_service = _context.GetOrCreateInstance()); - - public Data(IInitialContext context) - { - _context = context; - } - - public void Clear(bool dispose) - { - if (dispose && _service is IDisposable disposable) - disposable.Dispose(); + if (_storage.TryAdd(typeof(TService), new InitialContextData(context))) + return; - _service = null; - } + if (error) + throw new InvalidOperationException($"Service {typeof(TService)} already registered."); } - private class DefaultInitialContext : IInitialContext where T : class, IService + private class DefaultInitialContext : IInitialContext where TService : class, IService { - private Func _provider; + private Func _provider; - public DefaultInitialContext(Func provider) + public DefaultInitialContext(Func provider) { _provider = provider; } - T IInitialContext.GetOrCreateInstance() + TService IInitialContext.GetOrCreateInstance() { return _provider.Invoke(); } diff --git a/Code/Runtime/OlegHcp/Managing/ServiceLocatorDirty.cs b/Code/Runtime/OlegHcp/Managing/ServiceLocatorDirty.cs deleted file mode 100644 index 3015903b..00000000 --- a/Code/Runtime/OlegHcp/Managing/ServiceLocatorDirty.cs +++ /dev/null @@ -1,52 +0,0 @@ -#if !UNITY_2021_2_OR_NEWER -using OlegHcp.CSharp.Collections; -#endif - -namespace OlegHcp.Managing -{ - public class ServiceLocatorDirty : ServiceLocator - { - public bool RemoveInstance(bool dispose = true) where T : class, IService - { - if (_storage.TryGetValue(typeof(T), out Data value)) - { - value.Clear(dispose); - return true; - } - - return false; - } - - public void ClearInstances(bool dispose = true) - { - foreach (Data item in _storage.Values) - { - item.Clear(dispose); - } - } - - public bool Unregister(bool dispose = true) where T : class, IService - { - if (_storage.Remove(typeof(T), out Data value)) - { - value.Clear(dispose); - return true; - } - - return false; - } - - public void UnregisterAll(bool dispose = true) - { - if (dispose) - { - foreach (Data value in _storage.Values) - { - value.Clear(true); - } - } - - _storage.Clear(); - } - } -} From edc4dcd6d793e2a30dce2927cef14a7e3b7e4132 Mon Sep 17 00:00:00 2001 From: Oleg Pulkin Date: Mon, 25 Mar 2024 20:41:56 +0300 Subject: [PATCH 03/11] renaming --- Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs | 4 ++-- Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs | 4 ++-- Code/Runtime/OlegHcp/Managing/ServiceLocator.cs | 7 +++---- .../{InitialContextData.cs => ServiceLocatorData.cs} | 4 ++-- ...itialContextData.cs.meta => ServiceLocatorData.cs.meta} | 0 5 files changed, 9 insertions(+), 10 deletions(-) rename Code/Runtime/OlegHcp/Managing/{InitialContextData.cs => ServiceLocatorData.cs} (83%) rename Code/Runtime/OlegHcp/Managing/{InitialContextData.cs.meta => ServiceLocatorData.cs.meta} (100%) diff --git a/Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs b/Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs index f8e13239..9ad0c556 100644 --- a/Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs +++ b/Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs @@ -4,7 +4,7 @@ public class BoldServiceLocator : ServiceLocator { public bool RemoveInstance(bool dispose = true) where TService : class, IService { - if (_storage.TryGetValue(typeof(TService), out InitialContextData value)) + if (_storage.TryGetValue(typeof(TService), out ServiceLocatorData value)) { value.ClearInstance(dispose); return true; @@ -15,7 +15,7 @@ public bool RemoveInstance(bool dispose = true) where TService : class public void RemoveAllInstances(bool dispose = true) { - foreach (InitialContextData item in _storage.Values) + foreach (ServiceLocatorData item in _storage.Values) { item.ClearInstance(dispose); } diff --git a/Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs b/Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs index a24912b0..c2e38a45 100644 --- a/Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs +++ b/Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs @@ -8,7 +8,7 @@ public class DirtyServiceLocator : BoldServiceLocator { public bool Remove(bool dispose = true) where TService : class, IService { - if (_storage.Remove(typeof(TService), out InitialContextData value)) + if (_storage.Remove(typeof(TService), out ServiceLocatorData value)) { value.ClearInstance(dispose); return true; @@ -21,7 +21,7 @@ public void RemoveAll(bool dispose = true) { if (dispose) { - foreach (InitialContextData value in _storage.Values) + foreach (ServiceLocatorData value in _storage.Values) { value.ClearInstance(true); } diff --git a/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs b/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs index 9d1fb66e..047b67d3 100644 --- a/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs +++ b/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs @@ -3,7 +3,6 @@ using OlegHcp.Tools; using System.Runtime.Serialization; - #if !UNITY_2021_2_OR_NEWER using OlegHcp.CSharp.Collections; #endif @@ -19,11 +18,11 @@ public interface IInitialContext where TService : class, IService public class ServiceLocator { - private protected Dictionary _storage = new Dictionary(); + private protected Dictionary _storage = new Dictionary(); public TService Get(bool error = true) where TService : class, IService { - if (_storage.TryGetValue(typeof(TService), out InitialContextData value)) + if (_storage.TryGetValue(typeof(TService), out ServiceLocatorData value)) return (TService)value.Service; if (error) @@ -50,7 +49,7 @@ public void Add(Func instanceProvider, bool error = true) wh private void AddInternal(IInitialContext context, bool error) where TService : class, IService { - if (_storage.TryAdd(typeof(TService), new InitialContextData(context))) + if (_storage.TryAdd(typeof(TService), new ServiceLocatorData(context))) return; if (error) diff --git a/Code/Runtime/OlegHcp/Managing/InitialContextData.cs b/Code/Runtime/OlegHcp/Managing/ServiceLocatorData.cs similarity index 83% rename from Code/Runtime/OlegHcp/Managing/InitialContextData.cs rename to Code/Runtime/OlegHcp/Managing/ServiceLocatorData.cs index 72b96f62..506e73d9 100644 --- a/Code/Runtime/OlegHcp/Managing/InitialContextData.cs +++ b/Code/Runtime/OlegHcp/Managing/ServiceLocatorData.cs @@ -2,14 +2,14 @@ namespace OlegHcp.Managing { - internal class InitialContextData + internal class ServiceLocatorData { private IInitialContext _context; private IService _service; public IService Service => _service ?? (_service = _context.GetOrCreateInstance()); - public InitialContextData(IInitialContext context) + public ServiceLocatorData(IInitialContext context) { _context = context; } diff --git a/Code/Runtime/OlegHcp/Managing/InitialContextData.cs.meta b/Code/Runtime/OlegHcp/Managing/ServiceLocatorData.cs.meta similarity index 100% rename from Code/Runtime/OlegHcp/Managing/InitialContextData.cs.meta rename to Code/Runtime/OlegHcp/Managing/ServiceLocatorData.cs.meta From 1c25c17e6a804700acec191d4a364108626479d5 Mon Sep 17 00:00:00 2001 From: Oleg Pulkin Date: Mon, 25 Mar 2024 20:58:40 +0300 Subject: [PATCH 04/11] service locator README.md --- Code/Runtime/OlegHcp/Managing/README.md | 61 ++++++++++++++++++++ Code/Runtime/OlegHcp/Managing/README.md.meta | 7 +++ 2 files changed, 68 insertions(+) create mode 100644 Code/Runtime/OlegHcp/Managing/README.md create mode 100644 Code/Runtime/OlegHcp/Managing/README.md.meta diff --git a/Code/Runtime/OlegHcp/Managing/README.md b/Code/Runtime/OlegHcp/Managing/README.md new file mode 100644 index 00000000..eced02ae --- /dev/null +++ b/Code/Runtime/OlegHcp/Managing/README.md @@ -0,0 +1,61 @@ +## ServiceLocator + +```csharp +using OlegHcp.Managing; + +public static class Locator +{ + private static DirtyServiceLocator _serviceLocator = new DirtyServiceLocator(); + + public static ServiceLocator Current => _serviceLocator; + + public static void Clear() + { + _serviceLocator.RemoveAll(); + } +} +``` + +```csharp +using OlegHcp; +using UnityEngine; + +namespace Assets.PrivateStuff.Testing +{ + [DefaultExecutionOrder(-100)] + public class ExampleSceneConstructor : MonoBehaviour + { + [SerializeField] + private ServiceA _serviceA; + + private void Awake() + { + Locator.Current.Add(() => _serviceA); + Locator.Current.Add(() => new ServiceB()); + Locator.Current.Add(() => ComponentUtility.CreateInstance()); + } + + private void OnDestroy() + { + Locator.Clear(); + } + } +} +``` + +```csharp +using OlegHcp.Managing; +using UnityEngine; + +public class ExampleClass : MonoBehaviour +{ + private void Start() + { + IServiceA s1 = Locator.Current.Get(); + ServiceB s2 = Locator.Current.Get(); + ServiceC s3 = Locator.Current.Get(); + + // Do something + } +} +``` diff --git a/Code/Runtime/OlegHcp/Managing/README.md.meta b/Code/Runtime/OlegHcp/Managing/README.md.meta new file mode 100644 index 00000000..fcfb4319 --- /dev/null +++ b/Code/Runtime/OlegHcp/Managing/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 363bbd34edba3da42bdae075c9c9c9b0 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From 8f34e13ee37de06cd749fd5ba8ae614af4d8a469 Mon Sep 17 00:00:00 2001 From: Oleg Pulkin Date: Mon, 25 Mar 2024 21:03:07 +0300 Subject: [PATCH 05/11] upd --- Code/Runtime/OlegHcp/Managing/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/Code/Runtime/OlegHcp/Managing/README.md b/Code/Runtime/OlegHcp/Managing/README.md index eced02ae..0677e52d 100644 --- a/Code/Runtime/OlegHcp/Managing/README.md +++ b/Code/Runtime/OlegHcp/Managing/README.md @@ -44,7 +44,6 @@ namespace Assets.PrivateStuff.Testing ``` ```csharp -using OlegHcp.Managing; using UnityEngine; public class ExampleClass : MonoBehaviour From ff9a3d4d1a902fde06e76f2c6b615ab556707947 Mon Sep 17 00:00:00 2001 From: Oleg Pulkin Date: Mon, 25 Mar 2024 21:11:10 +0300 Subject: [PATCH 06/11] upd IsNullOrDead extension with replacing object with Unity object --- Code/Runtime/OlegHcp/Engine/UnityObjectExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Code/Runtime/OlegHcp/Engine/UnityObjectExtensions.cs b/Code/Runtime/OlegHcp/Engine/UnityObjectExtensions.cs index 961fa0ac..8969ebc3 100644 --- a/Code/Runtime/OlegHcp/Engine/UnityObjectExtensions.cs +++ b/Code/Runtime/OlegHcp/Engine/UnityObjectExtensions.cs @@ -97,12 +97,12 @@ public static Sprite ToSprite(this Texture2D self, float pixelsPerUnit = 100f, u return Sprite.Create(self, new Rect(0f, 0f, x, y), new Vector2(x * 0.5f, y * 0.5f), pixelsPerUnit, extrude, meshType, border); } - public static bool IsNullOrDead(this object self) + public static bool IsNullOrDead(this UnityObject self) { return UnityObjectUtility.IsNullOrDead(self); } - public static bool ExistsAndAlive(this object self) + public static bool ExistsAndAlive(this UnityObject self) { return !UnityObjectUtility.IsNullOrDead(self); } From 04ac2cdbc93d1f0ab04a75bfcdfd6cf1c945dade Mon Sep 17 00:00:00 2001 From: Oleg Pulkin Date: Mon, 25 Mar 2024 22:12:31 +0300 Subject: [PATCH 07/11] upd ServiceLocator --- .../OlegHcp/Managing/BoldServiceLocator.cs | 23 +++++-- .../OlegHcp/Managing/DirtyServiceLocator.cs | 26 ++------ .../OlegHcp/Managing/InitialContextStorage.cs | 61 +++++++++++++++++++ ....cs.meta => InitialContextStorage.cs.meta} | 2 +- .../OlegHcp/Managing/ServiceLocator.cs | 55 +++++++++++------ .../OlegHcp/Managing/ServiceLocatorData.cs | 25 -------- 6 files changed, 122 insertions(+), 70 deletions(-) create mode 100644 Code/Runtime/OlegHcp/Managing/InitialContextStorage.cs rename Code/Runtime/OlegHcp/Managing/{ServiceLocatorData.cs.meta => InitialContextStorage.cs.meta} (83%) delete mode 100644 Code/Runtime/OlegHcp/Managing/ServiceLocatorData.cs diff --git a/Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs b/Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs index 9ad0c556..f1ea1db5 100644 --- a/Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs +++ b/Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs @@ -1,12 +1,19 @@ -namespace OlegHcp.Managing +using System; + +#if !UNITY_2021_2_OR_NEWER +using OlegHcp.CSharp.Collections; +#endif + +namespace OlegHcp.Managing { public class BoldServiceLocator : ServiceLocator { public bool RemoveInstance(bool dispose = true) where TService : class, IService { - if (_storage.TryGetValue(typeof(TService), out ServiceLocatorData value)) + if (_serviceCache.Remove(typeof(TService), out IService service)) { - value.ClearInstance(dispose); + if (dispose && service is IDisposable disposable) + disposable.Dispose(); return true; } @@ -15,10 +22,16 @@ public bool RemoveInstance(bool dispose = true) where TService : class public void RemoveAllInstances(bool dispose = true) { - foreach (ServiceLocatorData item in _storage.Values) + if (dispose) { - item.ClearInstance(dispose); + foreach (IService service in _serviceCache.Values) + { + if (service is IDisposable disposable) + disposable.Dispose(); + } } + + _serviceCache.Clear(); } } } diff --git a/Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs b/Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs index c2e38a45..8f6d0e6b 100644 --- a/Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs +++ b/Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs @@ -1,33 +1,17 @@ -#if !UNITY_2021_2_OR_NEWER -using OlegHcp.CSharp.Collections; -#endif - -namespace OlegHcp.Managing +namespace OlegHcp.Managing { public class DirtyServiceLocator : BoldServiceLocator { public bool Remove(bool dispose = true) where TService : class, IService { - if (_storage.Remove(typeof(TService), out ServiceLocatorData value)) - { - value.ClearInstance(dispose); - return true; - } - - return false; + _contextCache.RemoveContext(); + return RemoveInstance(dispose); } public void RemoveAll(bool dispose = true) { - if (dispose) - { - foreach (ServiceLocatorData value in _storage.Values) - { - value.ClearInstance(true); - } - } - - _storage.Clear(); + _contextCache.Clear(); + RemoveAllInstances(dispose); } } } diff --git a/Code/Runtime/OlegHcp/Managing/InitialContextStorage.cs b/Code/Runtime/OlegHcp/Managing/InitialContextStorage.cs new file mode 100644 index 00000000..a2488294 --- /dev/null +++ b/Code/Runtime/OlegHcp/Managing/InitialContextStorage.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; + +#if !UNITY_2021_2_OR_NEWER +using OlegHcp.CSharp.Collections; +#endif + +namespace OlegHcp.Managing +{ + internal class InitialContextStorage + { + private ICommonInitialContext _commonContext; + private protected Dictionary _contextCache = new Dictionary(); + + public InitialContextStorage() + { + _commonContext = new DefaultInitialContext(); + } + + public InitialContextStorage(ICommonInitialContext commonContext) + { + _commonContext = commonContext; + } + + public bool TryGetOrCreateInstance(out TService service) where TService : class, IService + { + if (_contextCache.TryGetValue(typeof(TService), out object value)) + { + IInitialContext context = (IInitialContext)value; + service = context.GetOrCreateInstance(); + return true; + } + + return _commonContext.TryGetOrCreateInstance(out service); + } + + public bool AddContext(IInitialContext context) where TService : class, IService + { + return _contextCache.TryAdd(typeof(TService), context); + } + + public bool RemoveContext() where TService : class, IService + { + return _contextCache.Remove(typeof(TService)); + } + + public void Clear() + { + _contextCache.Clear(); + } + + private class DefaultInitialContext : ICommonInitialContext + { + bool ICommonInitialContext.TryGetOrCreateInstance(out TService service) + { + service = default; + return false; + } + } + } +} diff --git a/Code/Runtime/OlegHcp/Managing/ServiceLocatorData.cs.meta b/Code/Runtime/OlegHcp/Managing/InitialContextStorage.cs.meta similarity index 83% rename from Code/Runtime/OlegHcp/Managing/ServiceLocatorData.cs.meta rename to Code/Runtime/OlegHcp/Managing/InitialContextStorage.cs.meta index 1cb6c7e2..2087bc20 100644 --- a/Code/Runtime/OlegHcp/Managing/ServiceLocatorData.cs.meta +++ b/Code/Runtime/OlegHcp/Managing/InitialContextStorage.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 20cf25635a25e854fa0fc250ad6ac6a4 +guid: aa47c83147285e7428a66e20cdc15496 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs b/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs index 047b67d3..bf4b58c4 100644 --- a/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs +++ b/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs @@ -1,29 +1,49 @@ using System; using System.Collections.Generic; -using OlegHcp.Tools; using System.Runtime.Serialization; - -#if !UNITY_2021_2_OR_NEWER -using OlegHcp.CSharp.Collections; -#endif +using OlegHcp.Tools; namespace OlegHcp.Managing { public interface IService { } - public interface IInitialContext where TService : class, IService + public interface ICommonInitialContext + { + bool TryGetOrCreateInstance(out TService service) where TService : class, IService; + } + + public interface IInitialContext where TService : class, IService { TService GetOrCreateInstance(); } public class ServiceLocator { - private protected Dictionary _storage = new Dictionary(); + private protected InitialContextStorage _contextCache; + private protected Dictionary _serviceCache = new Dictionary(); + + public ServiceLocator() + { + _contextCache = new InitialContextStorage(); + } + + public ServiceLocator(ICommonInitialContext commonContext) + { + _contextCache = new InitialContextStorage(commonContext); + } public TService Get(bool error = true) where TService : class, IService { - if (_storage.TryGetValue(typeof(TService), out ServiceLocatorData value)) - return (TService)value.Service; + Type serviceType = typeof(TService); + + if (_serviceCache.TryGetValue(serviceType, out IService service)) + return (TService)service; + + if (_contextCache.TryGetOrCreateInstance(out TService newService)) + { + _serviceCache.Add(serviceType, newService); + return newService; + } if (error) throw ThrowErrors.ServiceNotRegistered(typeof(TService)); @@ -31,25 +51,24 @@ public TService Get(bool error = true) where TService : class, IServic return null; } - public void Add(IInitialContext context, bool error = true) where TService : class, IService + public void AddContext(IInitialContext context, bool error = true) where TService : class, IService { if (context == null) throw ThrowErrors.NullParameter(nameof(context)); - AddInternal(context, error); + if (_contextCache.AddContext(context)) + return; + + if (error) + throw new InvalidOperationException($"Service {typeof(TService)} already registered."); } - public void Add(Func instanceProvider, bool error = true) where TService : class, IService + public void AddContext(Func instanceProvider, bool error = true) where TService : class, IService { if (instanceProvider == null) throw ThrowErrors.NullParameter(nameof(instanceProvider)); - AddInternal(new DefaultInitialContext(instanceProvider), error); - } - - private void AddInternal(IInitialContext context, bool error) where TService : class, IService - { - if (_storage.TryAdd(typeof(TService), new ServiceLocatorData(context))) + if (_contextCache.AddContext(new DefaultInitialContext(instanceProvider))) return; if (error) diff --git a/Code/Runtime/OlegHcp/Managing/ServiceLocatorData.cs b/Code/Runtime/OlegHcp/Managing/ServiceLocatorData.cs deleted file mode 100644 index 506e73d9..00000000 --- a/Code/Runtime/OlegHcp/Managing/ServiceLocatorData.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; - -namespace OlegHcp.Managing -{ - internal class ServiceLocatorData - { - private IInitialContext _context; - private IService _service; - - public IService Service => _service ?? (_service = _context.GetOrCreateInstance()); - - public ServiceLocatorData(IInitialContext context) - { - _context = context; - } - - public void ClearInstance(bool dispose) - { - if (dispose && _service is IDisposable disposable) - disposable.Dispose(); - - _service = null; - } - } -} From 25ca988e9bfe1c55256a5f940937448bbe3b7868 Mon Sep 17 00:00:00 2001 From: Oleg Pulkin Date: Mon, 25 Mar 2024 22:31:38 +0300 Subject: [PATCH 08/11] upd ServiceLocator --- Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs | 4 ++++ Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs | 4 ++++ .../Runtime/OlegHcp/Managing/InitialContextStorage.cs | 11 +++++++++-- Code/Runtime/OlegHcp/Managing/ServiceLocator.cs | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs b/Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs index f1ea1db5..595282ce 100644 --- a/Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs +++ b/Code/Runtime/OlegHcp/Managing/BoldServiceLocator.cs @@ -8,6 +8,10 @@ namespace OlegHcp.Managing { public class BoldServiceLocator : ServiceLocator { + public BoldServiceLocator() { } + + public BoldServiceLocator(ICommonInitialContext commonContext) : base(commonContext) { } + public bool RemoveInstance(bool dispose = true) where TService : class, IService { if (_serviceCache.Remove(typeof(TService), out IService service)) diff --git a/Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs b/Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs index 8f6d0e6b..0e24c6b1 100644 --- a/Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs +++ b/Code/Runtime/OlegHcp/Managing/DirtyServiceLocator.cs @@ -2,6 +2,10 @@ { public class DirtyServiceLocator : BoldServiceLocator { + public DirtyServiceLocator() { } + + public DirtyServiceLocator(ICommonInitialContext commonContext) : base(commonContext) { } + public bool Remove(bool dispose = true) where TService : class, IService { _contextCache.RemoveContext(); diff --git a/Code/Runtime/OlegHcp/Managing/InitialContextStorage.cs b/Code/Runtime/OlegHcp/Managing/InitialContextStorage.cs index a2488294..e0f61eb6 100644 --- a/Code/Runtime/OlegHcp/Managing/InitialContextStorage.cs +++ b/Code/Runtime/OlegHcp/Managing/InitialContextStorage.cs @@ -31,7 +31,14 @@ public bool TryGetOrCreateInstance(out TService service) where TServic return true; } - return _commonContext.TryGetOrCreateInstance(out service); + if (_commonContext.TryGetOrCreateInstance(typeof(TService), out IService newService)) + { + service = (TService)newService; + return true; + } + + service = default; + return false; } public bool AddContext(IInitialContext context) where TService : class, IService @@ -51,7 +58,7 @@ public void Clear() private class DefaultInitialContext : ICommonInitialContext { - bool ICommonInitialContext.TryGetOrCreateInstance(out TService service) + bool ICommonInitialContext.TryGetOrCreateInstance(Type type, out IService service) { service = default; return false; diff --git a/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs b/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs index bf4b58c4..74d25153 100644 --- a/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs +++ b/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs @@ -9,7 +9,7 @@ public interface IService { } public interface ICommonInitialContext { - bool TryGetOrCreateInstance(out TService service) where TService : class, IService; + bool TryGetOrCreateInstance(Type serviceType, out IService service); } public interface IInitialContext where TService : class, IService From 0794a7822a1f0bbb13c62cedcd5c177f71cd6b1b Mon Sep 17 00:00:00 2001 From: Oleg Pulkin Date: Mon, 25 Mar 2024 22:41:14 +0300 Subject: [PATCH 09/11] upd ServiceLocator --- .../Runtime/OlegHcp/Managing/InitialContextStorage.cs | 11 ++--------- Code/Runtime/OlegHcp/Managing/ServiceLocator.cs | 6 +++--- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Code/Runtime/OlegHcp/Managing/InitialContextStorage.cs b/Code/Runtime/OlegHcp/Managing/InitialContextStorage.cs index e0f61eb6..4f63e1b7 100644 --- a/Code/Runtime/OlegHcp/Managing/InitialContextStorage.cs +++ b/Code/Runtime/OlegHcp/Managing/InitialContextStorage.cs @@ -22,7 +22,7 @@ public InitialContextStorage(ICommonInitialContext commonContext) _commonContext = commonContext; } - public bool TryGetOrCreateInstance(out TService service) where TService : class, IService + public bool TryGetOrCreateInstance(out IService service) where TService : class, IService { if (_contextCache.TryGetValue(typeof(TService), out object value)) { @@ -31,14 +31,7 @@ public bool TryGetOrCreateInstance(out TService service) where TServic return true; } - if (_commonContext.TryGetOrCreateInstance(typeof(TService), out IService newService)) - { - service = (TService)newService; - return true; - } - - service = default; - return false; + return _commonContext.TryGetOrCreateInstance(typeof(TService), out service); } public bool AddContext(IInitialContext context) where TService : class, IService diff --git a/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs b/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs index 74d25153..e42aff95 100644 --- a/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs +++ b/Code/Runtime/OlegHcp/Managing/ServiceLocator.cs @@ -39,10 +39,10 @@ public TService Get(bool error = true) where TService : class, IServic if (_serviceCache.TryGetValue(serviceType, out IService service)) return (TService)service; - if (_contextCache.TryGetOrCreateInstance(out TService newService)) + if (_contextCache.TryGetOrCreateInstance(out service)) { - _serviceCache.Add(serviceType, newService); - return newService; + _serviceCache.Add(serviceType, service); + return (TService)service; } if (error) From a00efe10ba0cf51595967e0ea9e200c63d37734f Mon Sep 17 00:00:00 2001 From: Oleg Pulkin Date: Mon, 25 Mar 2024 22:47:14 +0300 Subject: [PATCH 10/11] upd README.md --- Code/Runtime/OlegHcp/Managing/README.md | 2 ++ Code/Runtime/OlegHcp/Pool/README.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Code/Runtime/OlegHcp/Managing/README.md b/Code/Runtime/OlegHcp/Managing/README.md index 0677e52d..496b902e 100644 --- a/Code/Runtime/OlegHcp/Managing/README.md +++ b/Code/Runtime/OlegHcp/Managing/README.md @@ -16,6 +16,8 @@ public static class Locator } ``` +Stored services can be IDisposable. + ```csharp using OlegHcp; using UnityEngine; diff --git a/Code/Runtime/OlegHcp/Pool/README.md b/Code/Runtime/OlegHcp/Pool/README.md index 9d3ac4eb..7b4d5b6d 100644 --- a/Code/Runtime/OlegHcp/Pool/README.md +++ b/Code/Runtime/OlegHcp/Pool/README.md @@ -20,7 +20,7 @@ public class ExampleObject : MonoBehaviour, IPoolable } ``` -Stored object can be IDisposable. +Stored objects can be IDisposable. ```csharp using OlegHcp.Pool; From 843c34be80c9dcd210a54ab0db8cb3372239d860 Mon Sep 17 00:00:00 2001 From: Oleg Pulkin Date: Mon, 25 Mar 2024 22:47:56 +0300 Subject: [PATCH 11/11] upd package version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8794e345..9b794f0b 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "name": "Oleg Pulkin", "email": "oleghcp@gmail.com" }, - "version": "2.1.8", + "version": "2.2.0", "unity": "2019.4", "description": "A set of helpful code stuff for Unity.", "keywords": [ "oleghcp", "oleg", "hcp", "unitytools", "tools" ],