New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IAsyncLifetime support? #67
Comments
Can you provide sample code? |
Sure. This test not passing.
|
Oh, i see. |
The native xunit fixture injection does not work for injection in other fixtures. That was the main reason I used |
DI cannot call |
IHostedService used to run some background jobs alongside with app. In my case I just want some kind of async constructor and I'm not really sure how you suggest to use |
Use nest startup? |
I think it won't help. I'll try to explain what I need. But there are restrictions:
|
@MichaelLogutov think maybe the
And if you want to ensure your services start before running |
@WeihanLi If I understood correctly, this will ends up with me calling async code with |
@MichaelLogutov think it depends, we could try to avoid using async-based code in the constructor, move the async startup logic code into the I created a
|
Well, it could work yes. It's still not quite versatile as pytest fixtures because I need to register all those fixtures as global hosted services, which means they always created compared to pytest fixtures that will be initialized as needed. But it's still possible solution. Thanks. |
Sorry for the long delay, just got time to finally test your sample. Correct me if I'm wrong, but with you solution it will be required to manually write "wait for dependencies to be ready" loops? |
@MichaelLogutov sorry for the late reply yes, if you want to control the dependencies startup sequence exactly, I think we still need to wait for ready in a specific service. and there's edit:
|
Pity, but for now, I've ended up using service locator instead of constructor injection in test cases with this code:
This enabled to just write fixture with injection of any other fixture and upon creating instance DI container (SimpleInjector in this case) will ensure that InitializeAsync is called in the right order automatically. |
@pengweiqhca I have discovered that the It took me days to debug this issue and the solution was simply to use Also, I have not been able to inject a test fixture as a dependency of my test's dependency (effectively a nested fixture). More specifically, I wanted to inject the fixture when configuring public partial class Startup
{
public void ConfigureHost(IHostBuilder hostBuilder)
{
hostBuilder
.ConfigureServices(services =>
{
services.AddOptions<DependencyOptions>()
.Configure<TestFixture>((options, fixture) =>
{
options.Value = fixture.Value;
});
// ...
});
}
} Unfortunately, this doesn't work. Perhaps I should create a separate issue for this? |
I've ended up registering testcontainers fixtures as singletons and just blocking on async in constructor. |
Hello.
Is IAsyncLifetime supported? Because it seems InitializeAsync is not called for dependencies. Or is there an alternative way to invoke async initialization for fixtures (like databases)?
The text was updated successfully, but these errors were encountered: