using JT808.Gateway.Abstractions; using JT808.Gateway.Authorization; using JT808.Gateway.Abstractions.Configurations; using JT808.Gateway.Handlers; using JT808.Gateway.Internal; using JT808.Gateway.Services; using JT808.Gateway.Session; using JT808.Protocol; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using System; using System.Runtime.CompilerServices; using System.Linq; [assembly: InternalsVisibleTo("JT808.Gateway.TestHosting")] [assembly: InternalsVisibleTo("JT808.Gateway.Test")] namespace JT808.Gateway { /// /// JT808网关注册扩展 /// public static partial class JT808GatewayExtensions { /// /// 添加808网关 /// /// /// /// public static IJT808GatewayBuilder AddGateway(this IJT808Builder jT808Builder, Action config) { JT808GatewayBuilderDefault jT808GatewayBuilderDefault = new JT808GatewayBuilderDefault(jT808Builder); jT808GatewayBuilderDefault.JT808Builder.Services.Configure(config); jT808GatewayBuilderDefault.AddJT808Core(); return jT808GatewayBuilderDefault; } /// /// 添加808网关 /// /// /// /// public static IJT808GatewayBuilder AddGateway(this IJT808Builder jT808Builder, IConfiguration configuration) { JT808GatewayBuilderDefault jT808GatewayBuilderDefault = new JT808GatewayBuilderDefault(jT808Builder); jT808GatewayBuilderDefault.JT808Builder.Services.Configure(configuration.GetSection("JT808Configuration")); jT808GatewayBuilderDefault.AddJT808Core(); return jT808GatewayBuilderDefault; } /// /// 添加tcp服务器 /// /// /// public static IJT808GatewayBuilder AddTcp(this IJT808GatewayBuilder config) { config.JT808Builder.Services.AddHostedService(); config.JT808Builder.Services.AddHostedService(); return config; } /// /// 添加udp服务器 /// /// /// public static IJT808GatewayBuilder AddUdp(this IJT808GatewayBuilder config) { config.JT808Builder.Services.AddHostedService(); config.JT808Builder.Services.AddHostedService(); return config; } /// /// 添加http服务器 /// /// /// public static IJT808GatewayBuilder AddHttp(this IJT808GatewayBuilder config) { config.JT808Builder.Services.AddSingleton(); config.JT808Builder.Services.AddSingleton(); config.JT808Builder.Services.AddHostedService(); return config; } /// /// 添加http服务器 /// /// /// /// public static IJT808GatewayBuilder AddHttp(this IJT808GatewayBuilder config) where TJT808MsgIdDefaultWebApiHandler: JT808MsgIdDefaultWebApiHandler { config.JT808Builder.Services.AddSingleton(); config.JT808Builder.Services.AddSingleton(typeof(JT808MsgIdDefaultWebApiHandler),typeof(TJT808MsgIdDefaultWebApiHandler)); config.JT808Builder.Services.AddHostedService(); return config; } /// /// 添加消息业务处理程序 /// /// /// /// public static IJT808GatewayBuilder AddMessageHandler(this IJT808GatewayBuilder config) where TJT808MessageHandler : JT808MessageHandler { config.JT808Builder.Services.Replace(new ServiceDescriptor(typeof(JT808MessageHandler), typeof(TJT808MessageHandler), ServiceLifetime.Singleton)); return config; } /// /// 添加Http服务认证机制 /// /// /// /// public static IJT808GatewayBuilder AddHttpAuthorization(this IJT808GatewayBuilder config) where TJT808Authorization : IJT808Authorization { config.JT808Builder.Services.Replace(new ServiceDescriptor(typeof(IJT808Authorization), typeof(TJT808Authorization), ServiceLifetime.Singleton)); return config; } /// /// 添加消息生产者 /// /// /// /// public static IJT808GatewayBuilder AddMsgProducer(this IJT808GatewayBuilder config) where TJT808MsgProducer : IJT808MsgProducer { config.JT808Builder.Services.Replace(new ServiceDescriptor(typeof(IJT808MsgProducer), typeof(TJT808MsgProducer), ServiceLifetime.Singleton)); return config; } /// /// 添加消息应答后的应答生产者 /// /// /// /// public static IJT808GatewayBuilder AddMsgReplyLoggingProducer(this IJT808GatewayBuilder config) where TJT808MsgReplyLoggingProducer : IJT808MsgReplyLoggingProducer { config.JT808Builder.Services.Replace(new ServiceDescriptor(typeof(IJT808MsgReplyLoggingProducer), typeof(TJT808MsgReplyLoggingProducer), ServiceLifetime.Singleton)); return config; } /// /// 添加消息应答消费者 /// /// /// /// public static IJT808GatewayBuilder AddMsgReplyConsumer(this IJT808GatewayBuilder config) where TJT808MsgReplyConsumer : IJT808MsgReplyConsumer { config.JT808Builder.Services.Replace(new ServiceDescriptor(typeof(IJT808MsgReplyConsumer), typeof(TJT808MsgReplyConsumer), ServiceLifetime.Singleton)); return config; } /// /// 添加公共模块 /// /// /// private static IJT808GatewayBuilder AddJT808Core(this IJT808GatewayBuilder config) { config.JT808Builder.Services.AddSingleton(); config.JT808Builder.Services.AddSingleton(); config.JT808Builder.Services.AddSingleton(); config.JT808Builder.Services.AddSingleton(); config.JT808Builder.Services.AddSingleton(); config.JT808Builder.Services.AddSingleton(); config.JT808Builder.Services.AddHostedService(); return config; } } }