-
Notifications
You must be signed in to change notification settings - Fork 170
Open
Description
I love UnityMainThreadDispatcher; it solves a very simple problem well. However, I strongly dislike the static singleton anti-pattern used throughout the Unity ecosystem, and unfortunately this library is one of the culprits. I suggest adding the following interface:
public interface IUnityMainThreadDispatcher
{
void Enqueue(IEnumerator action);
void Enqueue(Action action);
Task EnqueueAsync(Action action);
}which the UnityMainThreadDispatcher class would implement. That way, developers can inject IUnityMainThreadDispatcher implementations (possibly their own) via dependency injection, mock it in unit tests, and generally avoid static cling in their code. This would not be a breaking change, as the static Instance method would still be present on the implementing class.
You can see my own version of this for reference in my personal UnityUtil library.
orosbogdan
Metadata
Metadata
Assignees
Labels
No labels