This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for updateable ActionDescriptorCollection
Fixes #5350
- Loading branch information
Showing
17 changed files
with
513 additions
and
51 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/IActionDescriptorChangeProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// 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 Microsoft.Extensions.Primitives; | ||
|
||
namespace Microsoft.AspNetCore.Mvc.Infrastructure | ||
{ | ||
/// <summary> | ||
/// Provides a way to signal invalidation of the cached collection of <see cref="Abstractions.ActionDescriptor" /> from an | ||
/// <see cref="IActionDescriptorCollectionProvider"/>. | ||
/// </summary> | ||
public interface IActionDescriptorChangeProvider | ||
{ | ||
/// <summary> | ||
/// Gets a <see cref="IChangeToken"/> used to signal invalidation of cached <see cref="Abstractions.ActionDescriptor"/> | ||
/// instances. | ||
/// </summary> | ||
/// <returns>The <see cref="IChangeToken"/>.</returns> | ||
IChangeToken GetChangeToken(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/Microsoft.AspNetCore.Mvc.Core/Internal/CompositeChangeToken.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// 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 Microsoft.Extensions.Primitives; | ||
|
||
namespace Microsoft.AspNetCore.Mvc.Internal | ||
{ | ||
internal class CompositeChangeToken : IChangeToken | ||
{ | ||
public CompositeChangeToken(IList<IChangeToken> changeTokens) | ||
{ | ||
if (changeTokens == null) | ||
{ | ||
throw new ArgumentNullException(nameof(changeTokens)); | ||
} | ||
|
||
ChangeTokens = changeTokens; | ||
} | ||
|
||
public IList<IChangeToken> ChangeTokens { get; } | ||
|
||
public IDisposable RegisterChangeCallback(Action<object> callback, object state) | ||
{ | ||
var disposables = new IDisposable[ChangeTokens.Count]; | ||
for (var i = 0; i < ChangeTokens.Count; i++) | ||
{ | ||
var disposable = ChangeTokens[i].RegisterChangeCallback(callback, state); | ||
disposables[i] = disposable; | ||
} | ||
return new CompositeDisposable(disposables); | ||
} | ||
|
||
public bool HasChanged | ||
{ | ||
get | ||
{ | ||
for (var i = 0; i < ChangeTokens.Count; i++) | ||
{ | ||
if (ChangeTokens[i].HasChanged) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
|
||
public bool ActiveChangeCallbacks | ||
{ | ||
get | ||
{ | ||
for (var i = 0; i < ChangeTokens.Count; i++) | ||
{ | ||
if (ChangeTokens[i].ActiveChangeCallbacks) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
|
||
private class CompositeDisposable : IDisposable | ||
{ | ||
private readonly IDisposable[] _disposables; | ||
|
||
public CompositeDisposable(IDisposable[] disposables) | ||
{ | ||
_disposables = disposables; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
for (var i = 0; i < _disposables.Length; i++) | ||
{ | ||
_disposables[i].Dispose(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.