Created
January 26, 2016 22:23
-
-
Save plioi/02efa966a306f26b9ab2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class TestDependencyScope | |
{ | |
private static IContainer _currentNestedContainer; | |
public static void Begin() | |
{ | |
if (_currentNestedContainer != null) | |
throw new Exception("Cannot begin test dependency scope. Another dependency scope is still in effect."); | |
_currentNestedContainer = IoC.Container.GetNestedContainer(); | |
} | |
public static IContainer CurrentNestedContainer | |
{ | |
get | |
{ | |
if (_currentNestedContainer == null) | |
throw new Exception($"Cannot access the {nameof(CurrentNestedContainer)}. There is no dependency scope in effect."); | |
return _currentNestedContainer; | |
} | |
} | |
public static void End() | |
{ | |
if (_currentNestedContainer == null) | |
throw new Exception("Cannot end test dependency scope. There is no dependency scope in effect."); | |
_currentNestedContainer.Dispose(); | |
_currentNestedContainer = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment