Skip to content

Commit

Permalink
feat(DependencyInjector): add RemoveInjector static method for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jonisavo committed May 27, 2022
1 parent 6b90eb2 commit e514533
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Assets/UIComponents.Tests/DependencyInjectorStaticTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,19 @@ public void TearDown()
);
}
}

[TestFixture]
public class RemoveInjector
{
[Test]
public void Removes_The_Injector_From_The_Dependency_Injector()
{
var componentType = typeof(UIComponentWithDependency);
var injector = new DependencyInjector();
DependencyInjector.InjectorDictionary[componentType] = injector;
DependencyInjector.RemoveInjector(componentType);
Assert.That(DependencyInjector.InjectorDictionary.ContainsKey(componentType), Is.False);
}
}
}
}
10 changes: 10 additions & 0 deletions Assets/UIComponents/Core/DependencyInjector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ public static DependencyInjector GetInjector(Type consumerType)
return CreateInjector(consumerType);
}

/// <summary>
/// Removes the injector of the given consumer type.
/// Used primarily for testing.
/// </summary>
/// <param name="consumerType">Consumer type</param>
public static void RemoveInjector(Type consumerType)
{
InjectorDictionary.Remove(consumerType);
}

private static DependencyInjector CreateInjector(Type consumerType)
{
var injectAttributes = (DependencyAttribute[])
Expand Down

0 comments on commit e514533

Please sign in to comment.