public async Task TestFixtureSetupTearDown() { await Task.WhenAll(_userServiceHost.CloseAsync(), _cancellationServiceHost.CloseAsync()).ConfigureAwait(false); ((IDisposable)_userServiceHost).Dispose(); ((IDisposable)_cancellationServiceHost).Dispose(); }
public async Task Fact1() { IServiceCollection services = new ServiceCollection(); services.AddScoped <ITestService, TestServicePerCall>(); services.AddSingleton(new Dependency { Initial = 1 }); using (var provider = services.BuildServiceProvider()) { using (ServiceHost host = new ServiceHost(typeof(TestServicePerCall), new Uri("net.tcp://localhost:5000"))) { host.AddServiceEndpoint(typeof(ITestService), binding, "/service1"); host.AddDependencyInjectionBehavior <ITestService>(provider); await host.OpenAsync(); using (var client = ChannelFactory <ITestServiceClient> .CreateChannel(binding, new EndpointAddress("net.tcp://localhost:5000/service1"))) { var result = client.Operation(); Assert.Equal(2, result); result = client.Operation(); Assert.Equal(2, result); } await host.CloseAsync(); } } }
async Task IHostedService.StopAsync(CancellationToken cancellationToken) { await host.CloseAsync(); using (host) { } }