当前位置: 首页>>代码示例>>C#>>正文


C# ServiceCollection.GetService方法代码示例

本文整理汇总了C#中ServiceCollection.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceCollection.GetService方法的具体用法?C# ServiceCollection.GetService怎么用?C# ServiceCollection.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ServiceCollection的用法示例。


在下文中一共展示了ServiceCollection.GetService方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Should_Be_Able_To_Nack_Message

		public async void Should_Be_Able_To_Nack_Message()
		{
			/* Setup */
			var service = new ServiceCollection()
				.AddRawRabbit<AdvancedMessageContext>()
				.BuildServiceProvider();

			var firstResponder = service.GetService<IBusClient<AdvancedMessageContext>>();
			var secondResponder = service.GetService<IBusClient<AdvancedMessageContext>>();
			var requester = service.GetService<IBusClient<AdvancedMessageContext>>();

			var hasBeenNacked = false;
			firstResponder.RespondAsync<BasicRequest, BasicResponse>((request, context) =>
			{
				BasicResponse response = null;
				if (!hasBeenNacked)
				{
					context?.Nack();
					hasBeenNacked = true;
				}
				else
				{
					response = new BasicResponse();
				}
				return Task.FromResult(response);
			}, c => c.WithNoAck(false));
			secondResponder.RespondAsync<BasicRequest, BasicResponse>((request, context) =>
			{
				BasicResponse response = null;
				if (!hasBeenNacked)
				{
					context?.Nack();
					hasBeenNacked = true;
				}
				else
				{
					response = new BasicResponse();
				}
				return Task.FromResult(response);
			}, c => c.WithNoAck(false));

			/* Test */
			var result = await requester.RequestAsync<BasicRequest, BasicResponse>(new BasicRequest(), configuration: cfg => cfg
					 .WithReplyQueue(
						 q => q.WithName("special_reply_queue")));

			/* Assert */
			Assert.NotNull(result);
			Assert.True(hasBeenNacked);
		}
开发者ID:enrique-avalon,项目名称:RawRabbit,代码行数:50,代码来源:NackingTests.cs

示例2: GetAdvancedBusClient

 public static IBusClient<AdvancedMessageContext> GetAdvancedBusClient()
 {
     /*
         There is no "simple" and "advanced" bus client in raw rabbit.
         The normal busclient is in fact just a IBusClient<MessageContext>
         which is kind of the same as the one we're returning here,
         with the difference that you get an "advanced context" where
         you can do some cool stuff.
     */
     var serviceProvider = new ServiceCollection()
         .AddRawRabbit<AdvancedMessageContext>()
         .AddSingleton<ILoggerFactory, VoidLoggerFactory>()
         .BuildServiceProvider();
     LogManager.CurrentFactory = serviceProvider.GetService<ILoggerFactory>();
     return serviceProvider.GetService<IBusClient<AdvancedMessageContext>>();
 }
开发者ID:pardahlman,项目名称:RabbitMqClientCompare,代码行数:16,代码来源:RawRabbitFactory.cs

示例3: Program

 public Program()
 {
     _consoleWriter = new ConsoleWriter();
     IServiceProvider serviceProvider = new ServiceCollection()
         .AddProceesProviderServices()
         .BuildServiceProvider();
     _executorProvider=serviceProvider.GetService<IProcessExecutorProvider>();
 }
开发者ID:jagasafari,项目名称:DevTools,代码行数:8,代码来源:Program.cs

示例4: TaskRunnerTests

        public TaskRunnerTests()
        {
            var lf = new LoggerFactory();
            lf.AddConsole();

            var serviceProvider = new ServiceCollection()
                .AddTransient(_ => new SampleTask(settings))
                .BuildServiceProvider();

            sampleTask = new TaskRunner<SampleTask>(lf, serviceProvider.GetService<IServiceScopeFactory>());
            sampleTask.Interval = TimeSpan.FromSeconds(5);
        }
开发者ID:justdmitry,项目名称:RecurrentTasks,代码行数:12,代码来源:TaskRunnerTests.cs

示例5: Should_Be_Able_To_Nack_On_Subscribe

		public async void Should_Be_Able_To_Nack_On_Subscribe()
		{
			/* Setup */
			var service = new ServiceCollection()
				.AddRawRabbit<AdvancedMessageContext>()
				.BuildServiceProvider();

			var subscriber = service.GetService<IBusClient<AdvancedMessageContext>>();
			var secondSubscriber = service.GetService<IBusClient<AdvancedMessageContext>>();
			var publisher = service.GetService<IBusClient<AdvancedMessageContext>>();
			var callcount = 0;
			var subscribeTcs = new TaskCompletionSource<bool>();
			var secondSubscribeTcs = new TaskCompletionSource<bool>();
			subscriber.SubscribeAsync<BasicMessage>((message, context) =>
			{
				Interlocked.Increment(ref callcount);
				context?.Nack();
				subscribeTcs.TrySetResult(true);
				return Task.FromResult(true);
			});
			secondSubscriber.SubscribeAsync<BasicMessage>((message, context) =>
			{
				secondSubscribeTcs.TrySetResult(true);
				return Task.FromResult(true);
			});

			Task.WaitAll(
				publisher.PublishAsync<BasicMessage>(),
				subscribeTcs.Task,
				secondSubscribeTcs.Task
			);

			TestChannel.QueueDelete("basicmessage");

			Assert.Equal(callcount, 1);
		}
开发者ID:enrique-avalon,项目名称:RawRabbit,代码行数:36,代码来源:NackingTests.cs

示例6: Non_generic_GetService_returns_null_if_service_not_registered

        public void Non_generic_GetService_returns_null_if_service_not_registered()
        {
            var serviceProvider = new ServiceCollection().BuildServiceProvider();

            Assert.Null(serviceProvider.GetService(typeof(IPilkington)));
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:6,代码来源:ServiceProviderExtensionsTest.cs

示例7: GetService_returns_null_if_service_not_registered

        public void GetService_returns_null_if_service_not_registered()
        {
            var serviceProvider = new ServiceCollection().BuildServiceProvider();

            Assert.Null(serviceProvider.GetService<IPilkington>());
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:6,代码来源:ServiceProviderExtensionsTest.cs


注:本文中的ServiceCollection.GetService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。