Skip to content

Instantly share code, notes, and snippets.

@b1ff
Last active August 29, 2015 14:02
Show Gist options
  • Save b1ff/0677b842aa38b42f3d8c to your computer and use it in GitHub Desktop.
Save b1ff/0677b842aa38b42f3d8c to your computer and use it in GitHub Desktop.
[Fact]
public void user_context_should_be_registered_per_dependency_scope()
{
EnsurePerScopeLifetime<IUserContext>();
}
private static void EnsurePerScopeLifetime<T>()
where T: class
{
var instance1 = TestBootstrapper.Instance.Get<T>();
var dependencyScope = TestBootstrapper.Instance.DependencyResolver.BeginScope();
var instance2 = dependencyScope.GetService(typeof (T)) as T;
instance1.Should().NotBeSameAs(instance2);
dependencyScope.GetService(typeof (T)).Should().BeSameAs(instance2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment