-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support hot reload for Blazor component endpoints
Support hot reload for Blazor component endpoints
- Loading branch information
1 parent
b86599e
commit e164c8a
Showing
11 changed files
with
322 additions
and
41 deletions.
There are no files selected for viewing
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
42 changes: 42 additions & 0 deletions
42
src/Components/Endpoints/src/DependencyInjection/HotReloadService.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,42 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Reflection.Metadata; | ||
using Microsoft.Extensions.Primitives; | ||
|
||
[assembly: MetadataUpdateHandler(typeof(Microsoft.AspNetCore.Components.Endpoints.HotReloadService))] | ||
|
||
namespace Microsoft.AspNetCore.Components.Endpoints; | ||
|
||
internal sealed class HotReloadService : IDisposable | ||
{ | ||
public HotReloadService() | ||
{ | ||
UpdateApplicationEvent += NotifyUpdateApplication; | ||
MetadataUpdateSupported = MetadataUpdater.IsSupported; | ||
} | ||
|
||
private CancellationTokenSource _tokenSource = new(); | ||
private static event Action<Type[]?>? UpdateApplicationEvent; | ||
|
||
public bool MetadataUpdateSupported { get; internal set; } | ||
|
||
public IChangeToken GetChangeToken() => new CancellationChangeToken(_tokenSource.Token); | ||
|
||
public static void UpdateApplication(Type[]? changedTypes) | ||
{ | ||
UpdateApplicationEvent?.Invoke(changedTypes); | ||
} | ||
|
||
private void NotifyUpdateApplication(Type[]? changedTypes) | ||
{ | ||
var current = Interlocked.Exchange(ref _tokenSource, new CancellationTokenSource()); | ||
current.Cancel(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
UpdateApplicationEvent -= NotifyUpdateApplication; | ||
_tokenSource.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
Oops, something went wrong.