Skip to content
Discussion options

You must be logged in to vote

Ok, I discovered by chance that you can do property injection in static properties. So I was able to make it work using this support class

[Binding]
public class TUnitDataBridgeSupport
{
    [ClassDataSource(Shared = [SharedType.PerTestSession])]
    public static WebApplicationFactory? Factory
    {
        get;
        set;
    }

    [BeforeTestRun]
    public static void RegisterFactoryInContainer(IObjectContainer objectContainer)
    {
        if (Factory == null)
        {
            throw new InvalidOperationException("Factory should have been initialized by the test framework before the test run starts.");
        }
        objectContainer.RegisterInstanceAs(Factory);
    }
}

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by srollinet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants