ServiceCollectionExtension.cs 971 B

123456789101112131415161718192021222324252627
  1. using Core.RabbitMQBus.Common;
  2. using Core.RabbitMQBus.EventBus;
  3. using Core.RabbitMQBus.Log;
  4. using Microsoft.Extensions.DependencyInjection;
  5. using System;
  6. namespace Core.RabbitMQBus.Extensions
  7. {
  8. public static class ServiceCollectionExtension
  9. {
  10. /// <summary>
  11. /// 注入RabbitMQ
  12. /// </summary>
  13. /// <param name="services"></param>
  14. /// <param name="options"></param>
  15. public static void RegisterRabbitMQ(this IServiceCollection services, Action<RabbitMQOptions> options)
  16. {
  17. services.Configure(options);
  18. services.AddSingleton<ILoggerHelper, ExceptionLessLogger>();
  19. services.AddSingleton<IConnectionChannel, ConnectionChannel>();
  20. services.AddSingleton<ISerializer, SwifterJsonSerializer>();
  21. services.AddSingleton<IRabbitMqPublisher, RabbitMqPublisher>();
  22. services.AddSingleton<IRabbitMqSubscriber, RabbitMqSubscriber>();
  23. }
  24. }
  25. }