//
// 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 System.IO.Pipes;
using Microsoft.Extensions.DependencyInjection;
using NosSmooth.Comms.Data;
namespace NosSmooth.Comms.NamedPipes.Extensions;
///
/// Extension methods for .
///
public static class ServiceCollectionExtensions
{
///
/// Adds a named pipe client as a .
///
/// The service collection.
/// A function for resolving the name of the pipe using service provider.
/// The same service collection.
public static IServiceCollection AddNamedPipeClient
(this IServiceCollection serviceCollection, Func pipeNameResolver)
=> serviceCollection
.AddSingleton(p => new NamedPipeClient(pipeNameResolver(p)))
.AddSingleton(p => p.GetRequiredService());
///
/// Adds a named pipe server as a .
///
/// The service collection.
/// A function for resolving the name of the pipe using service provider.
/// The same service collection.
public static IServiceCollection AddNamedPipeServer
(this IServiceCollection serviceCollection, Func pipeNameResolver)
=> serviceCollection
.AddSingleton(p => new NamedPipeServer(pipeNameResolver(p)))
.AddSingleton(p => p.GetRequiredService());
}