Skip to content

Commit

Permalink
Add public validation method
Browse files Browse the repository at this point in the history
  • Loading branch information
Anatoly Brizhan committed Mar 5, 2024
1 parent 7ca241c commit 7ffbdd0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Assets/BetterLocators/Runtime/Locator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public class Locator<TItem>
public virtual void Register<T>(T item) where T : TItem
{
var type = item.GetType();

if (_services.ContainsKey(type))
if (HasRegistered<T>())
{
var message = $"Service of type {type} is already registered. Operation cancelled";
Debug.LogError(message);
Expand All @@ -22,11 +21,16 @@ public virtual void Register<T>(T item) where T : TItem
_services[type] = item;
}

public virtual bool HasRegistered<T>() where T : TItem
{
var type = typeof(T);
return _services.ContainsKey(type);
}

public virtual void Unregister<T>(T service) where T : TItem
{
var type = service.GetType();

if (!_services.ContainsKey(type))
if (!HasRegistered<T>())
{
var message = $"Item of type {type} is not registered. Operation cancelled";
Debug.LogError(message);
Expand Down

0 comments on commit 7ffbdd0

Please sign in to comment.