FastTunnel/FastTunnel.Core.Client/Extensions/ServicesExtensions.cs

33 lines
1.1 KiB
C#
Raw Permalink Normal View History

2022-11-11 22:31:27 +08:00
// Licensed under the Apache License, Version 2.0 (the "License").
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE
// Copyright (c) 2019 Gui.H
using FastTunnel.Core.Config;
using FastTunnel.Core.Handlers.Client;
using FastTunnel.Core.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
2024-01-16 13:57:10 +08:00
namespace FastTunnel.Core.Client.Extensions;
public static class ServicesExtensions
2022-11-11 22:31:27 +08:00
{
2024-01-16 13:57:10 +08:00
/// <summary>
/// 客户端依赖及HostedService
/// </summary>
/// <param name="services"></param>
public static void AddFastTunnelClient(this IServiceCollection services, IConfigurationSection configurationSection)
2022-11-11 22:31:27 +08:00
{
2024-01-16 13:57:10 +08:00
services.Configure<DefaultClientConfig>(configurationSection);
2022-11-11 22:31:27 +08:00
2024-01-16 13:57:10 +08:00
services.AddTransient<IFastTunnelClient, FastTunnelClient>()
.AddSingleton<LogHandler>()
.AddSingleton<SwapHandler>();
2022-11-11 22:31:27 +08:00
2024-01-16 13:57:10 +08:00
services.AddHostedService<ServiceFastTunnelClient>();
2022-11-11 22:54:00 +08:00
}
2022-11-11 22:31:27 +08:00
}
2024-01-16 13:57:10 +08:00