#18 - Add interfaces for request lifetime management.
This commit is contained in:
parent
b751cf19d0
commit
8ad7b489e2
|
|
@ -2,6 +2,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Abstractions.Security;
|
using Microsoft.AspNet.Abstractions.Security;
|
||||||
|
|
||||||
|
|
@ -21,6 +22,10 @@ namespace Microsoft.AspNet.Abstractions
|
||||||
|
|
||||||
public abstract IServiceProvider RequestServices { get; set; }
|
public abstract IServiceProvider RequestServices { get; set; }
|
||||||
|
|
||||||
|
public abstract CancellationToken OnRequestAborted { get; }
|
||||||
|
|
||||||
|
public abstract void Abort();
|
||||||
|
|
||||||
public abstract void Dispose();
|
public abstract void Dispose();
|
||||||
|
|
||||||
public abstract object GetFeature(Type type);
|
public abstract object GetFeature(Type type);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.HttpFeature
|
||||||
|
{
|
||||||
|
public interface IHttpRequestLifetime
|
||||||
|
{
|
||||||
|
CancellationToken OnRequestAborted { get; }
|
||||||
|
void Abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
<Compile Include="IHttpBuffering.cs" />
|
<Compile Include="IHttpBuffering.cs" />
|
||||||
<Compile Include="IHttpConnection.cs" />
|
<Compile Include="IHttpConnection.cs" />
|
||||||
<Compile Include="IHttpRequestInformation.cs" />
|
<Compile Include="IHttpRequestInformation.cs" />
|
||||||
|
<Compile Include="IHttpRequestLifetime.cs" />
|
||||||
<Compile Include="IHttpResponseInformation.cs" />
|
<Compile Include="IHttpResponseInformation.cs" />
|
||||||
<Compile Include="IHttpSendFile.cs" />
|
<Compile Include="IHttpSendFile.cs" />
|
||||||
<Compile Include="IHttpTransportLayerSecurity.cs" />
|
<Compile Include="IHttpTransportLayerSecurity.cs" />
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,12 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Abstractions;
|
using Microsoft.AspNet.Abstractions;
|
||||||
using Microsoft.AspNet.Abstractions.Security;
|
using Microsoft.AspNet.Abstractions.Security;
|
||||||
using Microsoft.AspNet.FeatureModel;
|
using Microsoft.AspNet.FeatureModel;
|
||||||
|
using Microsoft.AspNet.HttpFeature;
|
||||||
using Microsoft.AspNet.HttpFeature.Security;
|
using Microsoft.AspNet.HttpFeature.Security;
|
||||||
using Microsoft.AspNet.PipelineCore.Infrastructure;
|
using Microsoft.AspNet.PipelineCore.Infrastructure;
|
||||||
using Microsoft.AspNet.PipelineCore.Security;
|
using Microsoft.AspNet.PipelineCore.Security;
|
||||||
|
|
@ -20,6 +22,7 @@ namespace Microsoft.AspNet.PipelineCore
|
||||||
private FeatureReference<ICanHasItems> _canHasItems;
|
private FeatureReference<ICanHasItems> _canHasItems;
|
||||||
private FeatureReference<ICanHasServiceProviders> _canHasServiceProviders;
|
private FeatureReference<ICanHasServiceProviders> _canHasServiceProviders;
|
||||||
private FeatureReference<IHttpAuthentication> _authentication;
|
private FeatureReference<IHttpAuthentication> _authentication;
|
||||||
|
private FeatureReference<IHttpRequestLifetime> _lifetime;
|
||||||
private IFeatureCollection _features;
|
private IFeatureCollection _features;
|
||||||
|
|
||||||
public DefaultHttpContext(IFeatureCollection features)
|
public DefaultHttpContext(IFeatureCollection features)
|
||||||
|
|
@ -48,6 +51,11 @@ namespace Microsoft.AspNet.PipelineCore
|
||||||
get { return _authentication.Fetch(_features) ?? _authentication.Update(_features, new DefaultHttpAuthentication()); }
|
get { return _authentication.Fetch(_features) ?? _authentication.Update(_features, new DefaultHttpAuthentication()); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IHttpRequestLifetime Lifetime
|
||||||
|
{
|
||||||
|
get { return _lifetime.Fetch(_features); }
|
||||||
|
}
|
||||||
|
|
||||||
public override HttpRequest Request { get { return _request; } }
|
public override HttpRequest Request { get { return _request; } }
|
||||||
|
|
||||||
public override HttpResponse Response { get { return _response; } }
|
public override HttpResponse Response { get { return _response; } }
|
||||||
|
|
@ -86,6 +94,28 @@ namespace Microsoft.AspNet.PipelineCore
|
||||||
|
|
||||||
public int Revision { get { return _features.Revision; } }
|
public int Revision { get { return _features.Revision; } }
|
||||||
|
|
||||||
|
public override CancellationToken OnRequestAborted
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var lifetime = Lifetime;
|
||||||
|
if (lifetime != null)
|
||||||
|
{
|
||||||
|
return lifetime.OnRequestAborted;
|
||||||
|
}
|
||||||
|
return CancellationToken.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Abort()
|
||||||
|
{
|
||||||
|
var lifetime = Lifetime;
|
||||||
|
if (lifetime != null)
|
||||||
|
{
|
||||||
|
lifetime.Abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
{
|
{
|
||||||
// REVIEW: is this necessary? is the environment "owned" by the context?
|
// REVIEW: is this necessary? is the environment "owned" by the context?
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,16 @@ namespace Microsoft.AspNet.Owin
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override CancellationToken OnRequestAborted
|
||||||
|
{
|
||||||
|
get { throw new NotImplementedException(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Abort()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MoqHttpRequest : HttpRequest, IHttpRequestInformation
|
private class MoqHttpRequest : HttpRequest, IHttpRequestInformation
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue