Aspnetcore: Question: How to get WebHost Start Uri when using the generic IHost?

Created on 17 Apr 2019  路  4Comments  路  Source: dotnet/aspnetcore

I am updating my E2E tests in blazor-state and my test application now uses the new Generic IHost in Program.cs

In my ServerFixture I was doing StartAndGetRootUri just like @SteveSandersonMS code.

protected override string StartAndGetRootUri()
        {
            _host = CreateWebHost();
            RunInBackgroundThread(_host.Start);
            return _host.ServerFeatures
                .Get<IServerAddressesFeature>()
                .Addresses.Single();
        }

With the new IHost I don't have ServerFeatures, So I am wondering how do we get the Addresss information from IHost?

If you update your DevHostServer You will be in the same boat.

I searched and couldn't figure out so asked where I thought it would be most helpful.

Thanks!

area-hosting

Most helpful comment

C# protected override string StartAndGetRootUri() { _host = CreateWebHost(); RunInBackgroundThread(_host.Start); return _host.Services.GetRequiredService<IServer>().Features .Get<IServerAddressesFeature>() .Addresses.Single(); }

All 4 comments

C# protected override string StartAndGetRootUri() { _host = CreateWebHost(); RunInBackgroundThread(_host.Start); return _host.Services.GetRequiredService<IServer>().Features .Get<IServerAddressesFeature>() .Addresses.Single(); }

@davidfowl Thanks I knew you guys would know. Now I guess I can do a PR to update your tests?

You mean to update the tests to use Host instead of WebHost? Sure, I think that would be OK.

It might be very hard but give it a shot.

cc @natemcmaster

Was this page helpful?
0 / 5 - 0 ratings