public async Task Transient_Should_Dispose() { DisposableActivationTestService testService = null; void ConfigureServices(IServiceCollection s) { s.AddTransient <IActivationTestService>(s => { testService = new DisposableActivationTestService(); return(testService); }); } var(host, connection) = CreateServerAndConnection(configureServices: ConfigureServices); host.PublishSingleton <IActivationTestService>(); host.Start(); try { var service = connection.GetServiceSingleton <IActivationTestService>(); service.Test(); Assert.NotNull(testService); await testService.WaitForDisposeAsync().DefaultTimeout(); Assert.AreEqual(1, testService.DisposeCount); await connection.ShutdownAsync(); } finally { await host.ShutdownAsync(); } }
public async Task ObjectFactory_Should_Dispose() { var(host, connection) = CreateServerAndConnection(configureServices: s => { }); host.PublishSingleton <IActivationTestService, DisposableActivationTestService>(); host.Start(); try { var service = connection.GetServiceSingleton <IActivationTestService>(); service.Test(); Assert.NotNull(s_disposableTestService); await s_disposableTestService.WaitForDisposeAsync().DefaultTimeout(); Assert.AreEqual(1, s_disposableTestService.DisposeCount); await connection.ShutdownAsync(); } finally { s_disposableTestService = null; await host.ShutdownAsync(); } }