зеркало из https://github.com/aspnet/Routing.git
Add GetChangeToken to EndpointDataSource (#649)
This commit is contained in:
Родитель
b9df95831d
Коммит
1e807240ea
|
@ -69,8 +69,8 @@ namespace Microsoft.AspNetCore.Routing
|
|||
foreach (var dataSource in _dataSources)
|
||||
{
|
||||
Extensions.Primitives.ChangeToken.OnChange(
|
||||
() => dataSource.ChangeToken,
|
||||
() => HandleChange());
|
||||
dataSource.GetChangeToken,
|
||||
HandleChange);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Routing
|
|||
{
|
||||
lock (_lock)
|
||||
{
|
||||
var changeToken = _dataSource.ChangeToken;
|
||||
var changeToken = _dataSource.GetChangeToken();
|
||||
_value = _initializeCore(_dataSource.Endpoints);
|
||||
|
||||
changeToken.RegisterChangeCallback(_initializerWithState, null);
|
||||
|
|
|
@ -8,7 +8,15 @@ namespace Microsoft.AspNetCore.Routing
|
|||
{
|
||||
public abstract class EndpointDataSource
|
||||
{
|
||||
public abstract IChangeToken ChangeToken { get; }
|
||||
public virtual IChangeToken ChangeToken { get; }
|
||||
|
||||
// Plan is to replace ChangeToken property with GetChangeToken
|
||||
// Temporarily have both to avoid breaking MVC
|
||||
// https://github.com/aspnet/Routing/issues/634
|
||||
public virtual IChangeToken GetChangeToken()
|
||||
{
|
||||
return ChangeToken;
|
||||
}
|
||||
|
||||
public abstract IReadOnlyList<Endpoint> Endpoints { get; }
|
||||
}
|
||||
|
|
|
@ -32,8 +32,8 @@ namespace Microsoft.AspNetCore.Routing
|
|||
|
||||
// Register for changes in endpoints
|
||||
Extensions.Primitives.ChangeToken.OnChange(
|
||||
() => _endpointDataSource.ChangeToken,
|
||||
() => HandleChange());
|
||||
_endpointDataSource.GetChangeToken,
|
||||
HandleChange);
|
||||
}
|
||||
|
||||
public IEnumerable<Endpoint> FindEndpoints(RouteValuesBasedEndpointFinderContext context)
|
||||
|
@ -70,8 +70,8 @@ namespace Microsoft.AspNetCore.Routing
|
|||
// re-register the callback as the change token is one time use only and a new change token
|
||||
// is produced every time
|
||||
Extensions.Primitives.ChangeToken.OnChange(
|
||||
() => _endpointDataSource.ChangeToken,
|
||||
() => HandleChange());
|
||||
_endpointDataSource.GetChangeToken,
|
||||
HandleChange);
|
||||
}
|
||||
|
||||
private void BuildOutboundMatches()
|
||||
|
|
|
@ -114,7 +114,7 @@ namespace Microsoft.AspNetCore.Routing
|
|||
var endpoints = compositeDataSource.Endpoints;
|
||||
|
||||
// Assert1
|
||||
var changeToken1 = compositeDataSource.ChangeToken;
|
||||
var changeToken1 = compositeDataSource.GetChangeToken();
|
||||
var token = Assert.IsType<CancellationChangeToken>(changeToken1);
|
||||
Assert.False(token.HasChanged); // initial state
|
||||
|
||||
|
@ -126,7 +126,7 @@ namespace Microsoft.AspNetCore.Routing
|
|||
|
||||
// Assert2
|
||||
Assert.True(changeToken1.HasChanged); // old token is expected to be changed
|
||||
var changeToken2 = compositeDataSource.ChangeToken; // new token is in a unchanged state
|
||||
var changeToken2 = compositeDataSource.GetChangeToken(); // new token is in a unchanged state
|
||||
Assert.NotSame(changeToken2, changeToken1);
|
||||
token = Assert.IsType<CancellationChangeToken>(changeToken2);
|
||||
Assert.False(token.HasChanged);
|
||||
|
@ -139,7 +139,7 @@ namespace Microsoft.AspNetCore.Routing
|
|||
|
||||
// Assert2
|
||||
Assert.True(changeToken2.HasChanged); // old token is expected to be changed
|
||||
var changeToken3 = compositeDataSource.ChangeToken; // new token is in a unchanged state
|
||||
var changeToken3 = compositeDataSource.GetChangeToken(); // new token is in a unchanged state
|
||||
Assert.NotSame(changeToken3, changeToken2);
|
||||
Assert.NotSame(changeToken3, changeToken1);
|
||||
token = Assert.IsType<CancellationChangeToken>(changeToken3);
|
||||
|
|
Загрузка…
Ссылка в новой задаче