51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using JiShe.CollectBus.Core.Plugins;
|
|
using JiShe.CollectBus.Core.Services;
|
|
using Microsoft.Extensions.Configuration;
|
|
using TouchSocket.Core;
|
|
using TouchSocket.Sockets;
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
namespace Microsoft.Extensions.DependencyInjection
|
|
{
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// 添加TcpService服务。
|
|
/// </summary>
|
|
public static IServiceCollection AddTcp(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
services.AddTcpService(config =>
|
|
{
|
|
config.SetListenIPHosts(int.Parse(configuration["TCP:ClientPort"] ?? "10500"))
|
|
.ConfigurePlugins(a =>
|
|
{
|
|
a.Add<TcpClosePlugin>();
|
|
a.Add<TcpServicePlugin>();
|
|
a.Add<BusService>();
|
|
});
|
|
});
|
|
return services;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 添加UdpService服务。
|
|
/// </summary>
|
|
public static IServiceCollection AddUdp(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
services.AddUdpSession(config =>
|
|
{
|
|
config.SetBindIPHost(int.Parse(configuration["UDP:ClientPort"] ?? "10500"))
|
|
.ConfigurePlugins(a =>
|
|
{
|
|
a.Add<UdpServicePlugin>();
|
|
a.Add<BusService>();
|
|
})
|
|
.UseBroadcast()
|
|
.SetUdpDataHandlingAdapter(() => new NormalUdpDataHandlingAdapter());
|
|
});
|
|
return services;
|
|
}
|
|
}
|
|
}
|