diff --git a/Assets/BetterLocators/Runtime/Locator.cs b/Assets/BetterLocators/Runtime/Locator.cs index 15aa069..51d7fde 100644 --- a/Assets/BetterLocators/Runtime/Locator.cs +++ b/Assets/BetterLocators/Runtime/Locator.cs @@ -11,8 +11,7 @@ public class Locator public virtual void Register(T item) where T : TItem { var type = item.GetType(); - - if (_services.ContainsKey(type)) + if (HasRegistered()) { var message = $"Service of type {type} is already registered. Operation cancelled"; Debug.LogError(message); @@ -22,11 +21,16 @@ public virtual void Register(T item) where T : TItem _services[type] = item; } + public virtual bool HasRegistered() where T : TItem + { + var type = typeof(T); + return _services.ContainsKey(type); + } + public virtual void Unregister(T service) where T : TItem { var type = service.GetType(); - - if (!_services.ContainsKey(type)) + if (!HasRegistered()) { var message = $"Item of type {type} is not registered. Operation cancelled"; Debug.LogError(message);