public static void InstanceContextMode_PerCall_NoInjection() { PerCallInstanceContextSimpleService.ClearCounts(); var services = new ServiceCollection(); string serviceAddress = "http://localhost/dummy"; var serviceDispatcher = TestHelper.BuildDispatcher <PerCallInstanceContextSimpleService>(services, serviceAddress); IChannel mockChannel = new MockReplyChannel(services.BuildServiceProvider()); var dispatcher = serviceDispatcher.CreateServiceChannelDispatcher(mockChannel); // Instance shouldn't be created as part of service startup as type isn't available in DI Assert.Equal(0, PerCallInstanceContextSimpleService.CreationCount); Assert.Equal(0, PerCallInstanceContextSimpleService.DisposalCount); var requestContext = TestRequestContext.Create(serviceAddress); dispatcher.DispatchAsync(requestContext, CancellationToken.None).Wait(); requestContext = TestRequestContext.Create(serviceAddress); dispatcher.DispatchAsync(requestContext, CancellationToken.None).Wait(); Assert.Equal(2, PerCallInstanceContextSimpleService.CreationCount); Assert.Equal(2, PerCallInstanceContextSimpleService.DisposalCount); }
public static void InstanceContextMode_PerCall_NoInjection() { PerCallInstanceContextSimpleService.ClearCounts(); System.ServiceModel.ChannelFactory <ISimpleService> factory = DispatcherHelper.CreateChannelFactory <PerCallInstanceContextSimpleService, ISimpleService>(); factory.Open(); ISimpleService channel = factory.CreateChannel(); ((System.ServiceModel.Channels.IChannel)channel).Open(); // Instance shouldn't be created as part of service startup as type isn't available in DI Assert.Equal(0, PerCallInstanceContextSimpleService.CreationCount); Assert.Equal(0, PerCallInstanceContextSimpleService.DisposalCount); string echo = channel.Echo("hello"); echo = channel.Echo("hello"); PerCallInstanceContextSimpleService.WaitForDisposalCount(2, TimeSpan.FromSeconds(30)); Assert.Equal(2, PerCallInstanceContextSimpleService.CreationCount); Assert.Equal(2, PerCallInstanceContextSimpleService.DisposalCount); ((System.ServiceModel.Channels.IChannel)channel).Close(); factory.Close(); TestHelper.CloseServiceModelObjects((System.ServiceModel.Channels.IChannel)channel, factory); }
public static void InstanceContextMode_PerCall_NoInjection() { PerCallInstanceContextSimpleService.ClearCounts(); var factory = ExtensibilityHelper.CreateChannelFactory <PerCallInstanceContextSimpleService, ISimpleService>(); factory.Open(); var channel = factory.CreateChannel(); ((System.ServiceModel.Channels.IChannel)channel).Open(); // Instance shouldn't be created as part of service startup as type isn't available in DI Assert.Equal(0, PerCallInstanceContextSimpleService.CreationCount); Assert.Equal(0, PerCallInstanceContextSimpleService.DisposalCount); var echo = channel.Echo("hello"); echo = channel.Echo("hello"); Assert.Equal(2, PerCallInstanceContextSimpleService.CreationCount); Assert.Equal(2, PerCallInstanceContextSimpleService.DisposalCount); ((System.ServiceModel.Channels.IChannel)channel).Close(); factory.Close(); TestHelper.CloseServiceModelObjects((System.ServiceModel.Channels.IChannel)channel, factory); }