aspnetcore/src/Servers/Connections.Abstractions/src/ConnectionContext.cs

32 lines
1.2 KiB
C#

// 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.Collections.Generic;
using System.IO.Pipelines;
using Microsoft.AspNetCore.Connections.Features;
using Microsoft.AspNetCore.Http.Features;
namespace Microsoft.AspNetCore.Connections
{
public abstract class ConnectionContext
{
public abstract string ConnectionId { get; set; }
public abstract IFeatureCollection Features { get; }
public abstract IDictionary<object, object> Items { get; set; }
public abstract IDuplexPipe Transport { get; set; }
public virtual void Abort(ConnectionAbortedException abortReason)
{
// We expect this to be overridden, but this helps maintain back compat
// with implementations of ConnectionContext that predate the addition of
// ConnectioContext.Abort()
Features.Get<IConnectionLifetimeFeature>()?.Abort();
}
public virtual void Abort() => Abort(new ConnectionAbortedException("The connection was aborted by the application."));
}
}