diff --git a/src/Components/Blazor/Blazor/src/Hosting/WebAssemblyHostBuilder.cs b/src/Components/Blazor/Blazor/src/Hosting/WebAssemblyHostBuilder.cs index 7e729f3bfb..7fa4dd0ae1 100644 --- a/src/Components/Blazor/Blazor/src/Hosting/WebAssemblyHostBuilder.cs +++ b/src/Components/Blazor/Blazor/src/Hosting/WebAssemblyHostBuilder.cs @@ -91,7 +91,6 @@ namespace Microsoft.AspNetCore.Blazor.Hosting services.AddSingleton(_BrowserHostBuilderContext); services.AddSingleton(); services.AddSingleton(WebAssemblyJSRuntime.Instance); - services.AddSingleton(); services.AddSingleton(WebAssemblyNavigationManager.Instance); services.AddSingleton(WebAssemblyNavigationInterception.Instance); services.AddSingleton(); diff --git a/src/Components/Blazor/Blazor/src/Services/WebAssemblyComponentContext.cs b/src/Components/Blazor/Blazor/src/Services/WebAssemblyComponentContext.cs deleted file mode 100644 index 0cc175dcde..0000000000 --- a/src/Components/Blazor/Blazor/src/Services/WebAssemblyComponentContext.cs +++ /dev/null @@ -1,12 +0,0 @@ -// 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.AspNetCore.Components; - -namespace Microsoft.AspNetCore.Blazor.Services -{ - internal class WebAssemblyComponentContext : IComponentContext - { - public bool IsConnected => true; - } -} diff --git a/src/Components/Blazor/Blazor/test/WebAssemblyComponentContextTest.cs b/src/Components/Blazor/Blazor/test/WebAssemblyComponentContextTest.cs deleted file mode 100644 index 3923dda5e6..0000000000 --- a/src/Components/Blazor/Blazor/test/WebAssemblyComponentContextTest.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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 Xunit; - -namespace Microsoft.AspNetCore.Blazor.Services.Test -{ - public class WebAssemblyComponentContextTest - { - [Fact] - public void IsConnected() - { - Assert.True(new WebAssemblyComponentContext().IsConnected); - } - } -} diff --git a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netcoreapp3.0.cs b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netcoreapp3.0.cs index 9448a45cb4..8d1cf57be2 100644 --- a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netcoreapp3.0.cs +++ b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netcoreapp3.0.cs @@ -196,10 +196,6 @@ namespace Microsoft.AspNetCore.Components void Attach(Microsoft.AspNetCore.Components.RenderHandle renderHandle); System.Threading.Tasks.Task SetParametersAsync(Microsoft.AspNetCore.Components.ParameterView parameters); } - public partial interface IComponentContext - { - bool IsConnected { get; } - } public partial interface IHandleAfterRender { System.Threading.Tasks.Task OnAfterRenderAsync(); diff --git a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs index 9448a45cb4..8d1cf57be2 100644 --- a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs +++ b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs @@ -196,10 +196,6 @@ namespace Microsoft.AspNetCore.Components void Attach(Microsoft.AspNetCore.Components.RenderHandle renderHandle); System.Threading.Tasks.Task SetParametersAsync(Microsoft.AspNetCore.Components.ParameterView parameters); } - public partial interface IComponentContext - { - bool IsConnected { get; } - } public partial interface IHandleAfterRender { System.Threading.Tasks.Task OnAfterRenderAsync(); diff --git a/src/Components/Components/src/IComponentContext.cs b/src/Components/Components/src/IComponentContext.cs deleted file mode 100644 index 879693eeb4..0000000000 --- a/src/Components/Components/src/IComponentContext.cs +++ /dev/null @@ -1,19 +0,0 @@ -// 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. - -namespace Microsoft.AspNetCore.Components -{ - /// - /// Provides information about the environment in which components are executing. - /// - public interface IComponentContext - { - /// - /// Gets a flag to indicate whether there is an active connection to the user's display. - /// - /// During prerendering, the value will always be false. - /// During server-side execution, the value can be true or false depending on whether there is an active SignalR connection. - /// During client-side execution, the value will always be true. - bool IsConnected { get; } - } -} diff --git a/src/Components/Components/src/Routing/Router.cs b/src/Components/Components/src/Routing/Router.cs index 42161ff828..ef34a47957 100644 --- a/src/Components/Components/src/Routing/Router.cs +++ b/src/Components/Components/src/Routing/Router.cs @@ -30,8 +30,6 @@ namespace Microsoft.AspNetCore.Components.Routing [Inject] private INavigationInterception NavigationInterception { get; set; } - [Inject] private IComponentContext ComponentContext { get; set; } - [Inject] private ILoggerFactory LoggerFactory { get; set; } /// @@ -152,7 +150,7 @@ namespace Microsoft.AspNetCore.Components.Routing Task IHandleAfterRender.OnAfterRenderAsync() { - if (!_navigationInterceptionEnabled && ComponentContext.IsConnected) + if (!_navigationInterceptionEnabled) { _navigationInterceptionEnabled = true; return NavigationInterception.EnableNavigationInterceptionAsync(); diff --git a/src/Components/Server/src/Circuits/DefaultCircuitFactory.cs b/src/Components/Server/src/Circuits/DefaultCircuitFactory.cs index b51f122278..cbeb6d2c7e 100644 --- a/src/Components/Server/src/Circuits/DefaultCircuitFactory.cs +++ b/src/Components/Server/src/Circuits/DefaultCircuitFactory.cs @@ -51,9 +51,7 @@ namespace Microsoft.AspNetCore.Components.Server.Circuits var scope = _scopeFactory.CreateScope(); var jsRuntime = (RemoteJSRuntime)scope.ServiceProvider.GetRequiredService(); - var componentContext = (RemoteComponentContext)scope.ServiceProvider.GetRequiredService(); jsRuntime.Initialize(client); - componentContext.Initialize(client); var navigationManager = (RemoteNavigationManager)scope.ServiceProvider.GetRequiredService(); var navigationInterception = (RemoteNavigationInterception)scope.ServiceProvider.GetRequiredService(); diff --git a/src/Components/Server/src/Circuits/RemoteComponentContext.cs b/src/Components/Server/src/Circuits/RemoteComponentContext.cs deleted file mode 100644 index 91a1b91710..0000000000 --- a/src/Components/Server/src/Circuits/RemoteComponentContext.cs +++ /dev/null @@ -1,19 +0,0 @@ -// 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; - -namespace Microsoft.AspNetCore.Components.Server.Circuits -{ - internal class RemoteComponentContext : IComponentContext - { - private CircuitClientProxy _clientProxy; - - public bool IsConnected => _clientProxy != null && _clientProxy.Connected; - - internal void Initialize(CircuitClientProxy clientProxy) - { - _clientProxy = clientProxy ?? throw new ArgumentNullException(nameof(clientProxy)); - } - } -} diff --git a/src/Components/Server/src/DependencyInjection/ComponentServiceCollectionExtensions.cs b/src/Components/Server/src/DependencyInjection/ComponentServiceCollectionExtensions.cs index 53c3be89bf..a9666ba8ba 100644 --- a/src/Components/Server/src/DependencyInjection/ComponentServiceCollectionExtensions.cs +++ b/src/Components/Server/src/DependencyInjection/ComponentServiceCollectionExtensions.cs @@ -70,7 +70,6 @@ namespace Microsoft.Extensions.DependencyInjection services.AddScoped(); services.AddScoped(); services.AddScoped(); - services.AddScoped(); services.AddScoped(); services.TryAddEnumerable(ServiceDescriptor.Singleton, CircuitOptionsJSInteropDetailedErrorsConfiguration>()); diff --git a/src/Components/Server/test/Circuits/RemoteComponentContextTest.cs b/src/Components/Server/test/Circuits/RemoteComponentContextTest.cs deleted file mode 100644 index ad97100b57..0000000000 --- a/src/Components/Server/test/Circuits/RemoteComponentContextTest.cs +++ /dev/null @@ -1,46 +0,0 @@ -// 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.Threading; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Components.Server.Circuits; -using Microsoft.AspNetCore.SignalR; -using Xunit; - -namespace Microsoft.AspNetCore.Components.Web.Rendering -{ - public class RemoteComponentContextTest - { - [Fact] - public void IfNotInitialized_IsConnectedReturnsFalse() - { - Assert.False(new RemoteComponentContext().IsConnected); - } - - [Fact] - public void IfInitialized_IsConnectedValueDeterminedByCircuitProxy() - { - // Arrange - var clientProxy = new FakeClientProxy(); - var circuitProxy = new CircuitClientProxy(clientProxy, "test connection"); - var remoteComponentContext = new RemoteComponentContext(); - - // Act/Assert: Can observe connected state - remoteComponentContext.Initialize(circuitProxy); - Assert.True(remoteComponentContext.IsConnected); - - // Act/Assert: Can observe disconnected state - circuitProxy.SetDisconnected(); - Assert.False(remoteComponentContext.IsConnected); - } - - private class FakeClientProxy : IClientProxy - { - public Task SendCoreAsync(string method, object[] args, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - } - } -} diff --git a/src/Components/test/testassets/BasicTestApp/InteropOnInitializationComponent.razor b/src/Components/test/testassets/BasicTestApp/InteropOnInitializationComponent.razor index b6c0b4e512..a108023ac7 100644 --- a/src/Components/test/testassets/BasicTestApp/InteropOnInitializationComponent.razor +++ b/src/Components/test/testassets/BasicTestApp/InteropOnInitializationComponent.razor @@ -1,7 +1,6 @@ @page "/prerendered-interop" @using Microsoft.AspNetCore.Components @using Microsoft.JSInterop -@inject IComponentContext ComponentContext @inject IJSRuntime JSRuntime

diff --git a/src/Components/test/testassets/BasicTestApp/PrerenderedToInteractiveTransition.razor b/src/Components/test/testassets/BasicTestApp/PrerenderedToInteractiveTransition.razor index 59020435e3..c2e2192ecd 100644 --- a/src/Components/test/testassets/BasicTestApp/PrerenderedToInteractiveTransition.razor +++ b/src/Components/test/testassets/BasicTestApp/PrerenderedToInteractiveTransition.razor @@ -1,7 +1,6 @@ @page "/prerendered-transition" @using Microsoft.AspNetCore.Components @using Microsoft.AspNetCore.Components.Authorization -@inject IComponentContext ComponentContext @@ -11,7 +10,7 @@

Current state: - @(ComponentContext.IsConnected ? "connected" : "not connected") + @(hasRenderedInConnectedMode ? "connected" : "not connected")

@@ -22,11 +21,13 @@ @code { + bool hasRenderedInConnectedMode; int count; protected override Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { + hasRenderedInConnectedMode = true; // We need to queue another render when we connect, otherwise the // browser won't see anything. StateHasChanged(); diff --git a/src/Mvc/Mvc.ViewFeatures/src/DependencyInjection/MvcViewFeaturesMvcCoreBuilderExtensions.cs b/src/Mvc/Mvc.ViewFeatures/src/DependencyInjection/MvcViewFeaturesMvcCoreBuilderExtensions.cs index e62b839f82..7bd517c1f1 100644 --- a/src/Mvc/Mvc.ViewFeatures/src/DependencyInjection/MvcViewFeaturesMvcCoreBuilderExtensions.cs +++ b/src/Mvc/Mvc.ViewFeatures/src/DependencyInjection/MvcViewFeaturesMvcCoreBuilderExtensions.cs @@ -208,7 +208,6 @@ namespace Microsoft.Extensions.DependencyInjection services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); - services.TryAddScoped(); services.TryAddScoped(); services.TryAddTransient(); diff --git a/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/UnsupportedComponentContext.cs b/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/UnsupportedComponentContext.cs deleted file mode 100644 index 86220830e6..0000000000 --- a/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/UnsupportedComponentContext.cs +++ /dev/null @@ -1,12 +0,0 @@ -// 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.AspNetCore.Components; - -namespace Microsoft.AspNetCore.Mvc.ViewFeatures -{ - internal class UnsupportedComponentContext : IComponentContext - { - public bool IsConnected => false; - } -}