VContainer
VContainer copied to clipboard
Destroy LifetimeScope in Editor
I was writing an editor test where my sut calls Dispose on a LifetimeScope, which throws because it uses Destroy instead of DestroyImmediate.
This small override seems to fix it:
public class EditorSafeLifetimeScope : LifetimeScope
{
public new void Dispose()
{
DisposeCore();
if (this != null)
{
#if UNITY_EDITOR
if (!Application.isPlaying)
{
DestroyImmediate(gameObject);
return;
}
#endif
Destroy(gameObject);
}
}
}