-
|
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 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Try using Data sources are created at discovery time. |
Beta Was this translation helpful? Give feedback.
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