|
hii here's what i came up with: public class TestDependencyInjectionAttribute : DependencyInjectionDataSourceAttribute<IServiceScope>
{
private IServiceProvider? _serviceProvider;
[ClassDataSource<DatabaseFixture>(Shared = SharedType.PerClass)]
public DatabaseFixture Database { get; init; }
public override IServiceScope CreateScope(DataGeneratorMetadata dataGeneratorMetadata)
{
if (_serviceProvider is null)
{
var services = new ServiceCollection();
services
.AddScoped<DatabaseContext>(_ => Database.CreateContext())but this code fails because it seems like InitializeAsync was not called for the Database. is this a bug, and should i even try to do that? i just thought i could inject my dependencies into the test classes using the constructor instead of injecting the service collection my TUnit version is 1.13 and i'm using .NET 10 |
Answered by
thomhurst
Feb 7, 2026
Replies: 1 comment
|
Try using Data sources are created at discovery time. |
0 replies
Answer selected by
Dubzer
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try using
IAsyncDiscoveryInitializerinstead ofIAsyncInitializer.Data sources are created at discovery time.
IAsyncInitializerruns just before a test starts, so you'll need the earlier discovery version instead