// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Protocols; namespace Microsoft.AspNetCore.Sockets { public class ConnectionBuilder : IConnectionBuilder { private readonly IList> _components = new List>(); public IServiceProvider ApplicationServices { get; } public ConnectionBuilder(IServiceProvider applicationServices) { ApplicationServices = applicationServices; } public IConnectionBuilder Use(Func middleware) { _components.Add(middleware); return this; } public ConnectionDelegate Build() { ConnectionDelegate app = features => { return Task.CompletedTask; }; foreach (var component in _components.Reverse()) { app = component(app); } return app; } } }