Merge pull request #471 from benaadams/lazy-init

Lazily initialize DefaultHttpContext
This commit is contained in:
David Fowler 2015-11-10 07:20:52 -08:00
commit 466ca57d4b
1 changed files with 24 additions and 6 deletions

View File

@ -18,8 +18,8 @@ namespace Microsoft.AspNet.Http.Internal
{
private readonly HttpRequest _request;
private readonly HttpResponse _response;
private readonly ConnectionInfo _connection;
private readonly AuthenticationManager _authenticationManager;
private ConnectionInfo _connection;
private AuthenticationManager _authenticationManager;
private IItemsFeature _items;
private IServiceProvidersFeature _serviceProviders;
@ -43,8 +43,6 @@ namespace Microsoft.AspNet.Http.Internal
_features = features;
_request = new DefaultHttpRequest(this, features);
_response = new DefaultHttpResponse(this, features);
_connection = new DefaultConnectionInfo(features);
_authenticationManager = new DefaultAuthenticationManager(features);
}
void IFeatureCache.CheckFeaturesRevision()
@ -133,9 +131,29 @@ namespace Microsoft.AspNet.Http.Internal
public override HttpResponse Response { get { return _response; } }
public override ConnectionInfo Connection { get { return _connection; } }
public override ConnectionInfo Connection
{
get
{
if (_connection == null)
{
_connection = new DefaultConnectionInfo(_features);
}
return _connection;
}
}
public override AuthenticationManager Authentication { get { return _authenticationManager; } }
public override AuthenticationManager Authentication
{
get
{
if (_authenticationManager == null)
{
_authenticationManager = new DefaultAuthenticationManager(_features);
}
return _authenticationManager;
}
}
public override ClaimsPrincipal User
{