Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

74 строки
2.6 KiB

  1. using JT808.Protocol.Interfaces;
  2. using JT808.Protocol.Internal;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. namespace JT808.Protocol
  8. {
  9. /// <summary>
  10. /// DI扩展
  11. /// </summary>
  12. public static class DependencyInjectionExtensions
  13. {
  14. /// <summary>
  15. /// 注册808配置
  16. /// </summary>
  17. /// <param name="services"></param>
  18. /// <param name="jT808Config"></param>
  19. /// <returns></returns>
  20. public static IJT808Builder AddJT808Configure(this IServiceCollection services, IJT808Config jT808Config)
  21. {
  22. services.AddSingleton(jT808Config.GetType(), jT808Config);
  23. return new DefaultBuilder(services, jT808Config);
  24. }
  25. /// <summary>
  26. /// 注册808配置
  27. /// </summary>
  28. /// <param name="builder"></param>
  29. /// <param name="jT808Config"></param>
  30. /// <returns></returns>
  31. public static IJT808Builder AddJT808Configure(this IJT808Builder builder, IJT808Config jT808Config)
  32. {
  33. builder.Services.AddSingleton(jT808Config.GetType(), jT808Config);
  34. return builder;
  35. }
  36. /// <summary>
  37. /// 注册808配置
  38. /// </summary>
  39. /// <typeparam name="TJT808Config"></typeparam>
  40. /// <param name="services"></param>
  41. /// <returns></returns>
  42. public static IJT808Builder AddJT808Configure<TJT808Config>(this IServiceCollection services)where TJT808Config : IJT808Config,new()
  43. {
  44. var config = new TJT808Config();
  45. services.AddSingleton(typeof(TJT808Config), config);
  46. return new DefaultBuilder(services, config);
  47. }
  48. /// <summary>
  49. /// 注册808配置
  50. /// </summary>
  51. /// <typeparam name="TJT808Config"></typeparam>
  52. /// <param name="builder"></param>
  53. /// <returns></returns>
  54. public static IJT808Builder AddJT808Configure<TJT808Config>(this IJT808Builder builder) where TJT808Config : IJT808Config, new()
  55. {
  56. var config = new TJT808Config();
  57. builder.Services.AddSingleton(typeof(TJT808Config), config);
  58. return builder;
  59. }
  60. /// <summary>
  61. /// 注册808配置
  62. /// </summary>
  63. /// <param name="services"></param>
  64. /// <returns></returns>
  65. public static IJT808Builder AddJT808Configure(this IServiceCollection services)
  66. {
  67. DefaultGlobalConfig config = new DefaultGlobalConfig();
  68. services.AddSingleton<IJT808Config>(config);
  69. return new DefaultBuilder(services, config);
  70. }
  71. }
  72. }