~ruther/NosSmooth.Local

ref: 13d498f7ac7588f5f5d7455ca94d9f9ef7fc74e8 NosSmooth.Local/src/Core/NosSmooth.LocalClient/Extensions/ServiceCollectionExtensions.cs -rw-r--r-- 2.1 KiB
13d498f7 — Rutherther feat(client): add attack command handler 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
//  ServiceCollectionExtensions.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using NosSmooth.Core.Client;
using NosSmooth.Core.Extensions;
using NosSmooth.LocalBinding.Extensions;
using NosSmooth.LocalClient.CommandHandlers.Attack;
using NosSmooth.LocalClient.CommandHandlers.Walk;

namespace NosSmooth.LocalClient.Extensions;

/// <summary>
/// Contains extension methods for <see cref="IServiceCollection"/>.
/// </summary>
public static class ServiceCollectionExtensions
{
    /// <summary>
    /// Adds <see cref="NostaleLocalClient"/> along with all core dependencies.
    /// </summary>
    /// <param name="serviceCollection">The service collection.</param>
    /// <returns>The collection.</returns>
    public static IServiceCollection AddLocalClient(this IServiceCollection serviceCollection)
    {
        serviceCollection.AddNostaleCore();
        serviceCollection.AddNostaleBindings();
        serviceCollection
            .AddTakeControlCommand()
            .AddCommandHandler<AttackCommandHandler>()
            .AddCommandHandler<PlayerWalkCommandHandler>()
            .AddCommandHandler<PetWalkCommandHandler>();
        serviceCollection.TryAddSingleton<NostaleLocalClient>();
        serviceCollection.TryAddSingleton<INostaleClient>(p => p.GetRequiredService<NostaleLocalClient>());

        return serviceCollection;
    }

    /// <summary>
    /// Adds packet interceptor.
    /// </summary>
    /// <param name="serviceCollection">The service collection.</param>
    /// <typeparam name="TInterceptor">The type of the interceptor.</typeparam>
    /// <returns>The collection.</returns>
    public static IServiceCollection AddPacketInterceptor<TInterceptor>(this IServiceCollection serviceCollection)
        where TInterceptor : class, IPacketInterceptor
    {
        return serviceCollection.AddSingleton<IPacketInterceptor, TInterceptor>();
    }
}
Do not follow this link