Created
July 15, 2020 23:44
-
-
Save dcomartin/93bded60711e73b8e68ad54ad84867b1 to your computer and use it in GitHub Desktop.
This file contains 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 class ScopedLifetimeTest | |
{ | |
[Fact] | |
public async Task ShouldShitTheBed() | |
{ | |
var serviceCollection = new ServiceCollection(); | |
serviceCollection.AddScoped<ClassA>(); | |
serviceCollection.AddScoped<ClassB>(); | |
serviceCollection.AddScoped<ClassC>(); | |
var provider = serviceCollection.BuildServiceProvider(); | |
var classA = provider.GetService<ClassA>(); | |
var result = await classA.DoWork(); | |
// This will fail because it will return 0. | |
// This is because ClassB sets the _state member second, but finishes first. | |
// ClassA finishes last and returns _state.length which is now blank because ClassB has already run. | |
result.ShouldBe(4); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment