Replies: 2 comments 1 reply
-
You get a new instance of a class for each test, so class constructors should still work |
Beta Was this translation helpful? Give feedback.
-
@thomhurst thanks for following up! Yes you are correct, each test it seems to fire up a new instance of the Test Class, and thus DI's new services and they have their own public class DependencyInjectionClassConstructor : IClassConstructor, ITestEndEvent
{
private static readonly IServiceProvider _serviceProvider = CreateServiceProvider();
...
} This suggests (given my dotnet/C# understanding) that the I noted at runtime, running tests in parallel, that singletons that maintained By reverting the code to to make the public class DependencyInjectionClassConstructor : IClassConstructor, ITestEndEvent
{
private readonly IServiceProvider _serviceProvider = CreateServiceProvider();
...
} Seems to solve the issue! It may be that the documentation needs updating? Thanks again for putting this package together. |
Beta Was this translation helpful? Give feedback.
-
Hi All - love the lib....
Setting up integration tests that are heavily dependent on DI and leveraging the ClassConstructors as documented with DotNet DI Service Provider.
However I really need to be able to DI on a "by test" basis, not by class, as I need the services to all be isolated between tests.
I was figuring I probably need to use the Property Injection sync that I can control the scope, and possibly a ClassDataSource but can figure how to hook this up.
Is this in fact possible, or what other approaches do you recommend?
Beta Was this translation helpful? Give feedback.
All reactions