Skip to content

Remove Entrypoint Invoker #31769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
8 commits merged into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Components/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/Samples/**/.vscode/*
2 changes: 1 addition & 1 deletion src/Components/Web.JS/dist/Release/blazor.server.js

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,13 @@ export const monoPlatform: Platform = {
});
},

callEntryPoint: function callEntryPoint(assemblyName: string) {
// Instead of using Module.mono_call_assembly_entry_point, we have our own logic for invoking
// the entrypoint which adds support for async main.
callEntryPoint: function callEntryPoint(assemblyName: string) : Promise<any> {
// Currently we disregard the return value from the entrypoint, whether it's sync or async.
// In the future, we might want Blazor.start to return a Promise<Promise<value>>, where the
// outer promise reflects the startup process, and the inner one reflects the possibly-async
// .NET entrypoint method.
const invokeEntrypoint = bindStaticMethod('Microsoft.AspNetCore.Components.WebAssembly', 'Microsoft.AspNetCore.Components.WebAssembly.Hosting.EntrypointInvoker', 'InvokeEntrypoint');
// Note we're passing in null because passing arrays is problematic until https://github.com/mono/mono/issues/18245 is resolved.
invokeEntrypoint(assemblyName, null);
const emptyArray = [ [ ] ];
return BINDING.call_assembly_entry_point(assemblyName, emptyArray, undefined);
},

toUint8Array: function toUint8Array(array: System_Array<any>): Uint8Array {
Expand Down
1 change: 1 addition & 0 deletions src/Components/Web.JS/src/Platform/Mono/MonoTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ declare interface BINDING {
mono_array_to_js_array<TInput, TOutput>(array: System_Array<TInput>) : Array<TOutput>;
conv_string(dotnetString: System_String | null): string | null;
bind_static_method(fqn: string, signature?: string): Function;
call_assembly_entry_point(assemblyName: string, args: any[], signature: any): Promise<any>;
unbox_mono_obj(object: System_Object): any;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ internal WebAssemblyHost(
string? persistedState)
{
// To ensure JS-invoked methods don't get linked out, have a reference to their enclosing types
GC.KeepAlive(typeof(EntrypointInvoker));
GC.KeepAlive(typeof(JSInteropMethods));

_services = services;
Expand All @@ -68,8 +67,6 @@ internal WebAssemblyHost(
/// </summary>
public IServiceProvider Services => _scope.ServiceProvider;

internal WebAssemblyCultureProvider CultureProvider { get; set; } = WebAssemblyCultureProvider.Instance!;

/// <summary>
/// Disposes the host asynchronously.
/// </summary>
Expand Down Expand Up @@ -124,7 +121,7 @@ public Task RunAsync()
}

// Internal for testing.
internal async Task RunAsyncCore(CancellationToken cancellationToken)
internal async Task RunAsyncCore(CancellationToken cancellationToken, WebAssemblyCultureProvider? cultureProvider = null)
{
if (_started)
{
Expand All @@ -133,13 +130,13 @@ internal async Task RunAsyncCore(CancellationToken cancellationToken)

_started = true;

CultureProvider.ThrowIfCultureChangeIsUnsupported();
cultureProvider ??= WebAssemblyCultureProvider.Instance!;
cultureProvider.ThrowIfCultureChangeIsUnsupported();

// EntryPointInvoker loads satellite assemblies for the application default culture.
// Application developers might have configured the culture based on some ambient state
// such as local storage, url etc as part of their Program.Main(Async).
// This is the earliest opportunity to fetch satellite assemblies for this selection.
await CultureProvider.LoadCurrentCultureResourcesAsync();
await cultureProvider.LoadCurrentCultureResourcesAsync();

var manager = Services.GetRequiredService<ComponentApplicationLifetime>();
var store = !string.IsNullOrEmpty(_persistedState) ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public sealed class WebAssemblyHostBuilder
/// </summary>
/// <param name="args">The argument passed to the application's main method.</param>
/// <returns>A <see cref="WebAssemblyHostBuilder"/>.</returns>
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicMethods, typeof(EntrypointInvoker))]
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicMethods, typeof(JSInteropMethods))]
[DynamicDependency(JsonSerialized, typeof(WebEventDescriptor))]
public static WebAssemblyHostBuilder CreateDefault(string[]? args = default)
Expand All @@ -46,6 +45,8 @@ public static WebAssemblyHostBuilder CreateDefault(string[]? args = default)
args ??= Array.Empty<string>();
var builder = new WebAssemblyHostBuilder(DefaultWebAssemblyJSRuntime.Instance);

WebAssemblyCultureProvider.Initialize();

// Right now we don't have conventions or behaviors that are specific to this method
// however, making this the default for the template allows us to add things like that
// in the future, while giving `new WebAssemblyHostBuilder` as an opt-out of opinionated
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public async Task RunAsync_CanExitBasedOnCancellationToken()
// Arrange
var builder = new WebAssemblyHostBuilder(new TestJSUnmarshalledRuntime());
var host = builder.Build();
host.CultureProvider = new TestSatelliteResourcesLoader();
var cultureProvider = new TestSatelliteResourcesLoader();

var cts = new CancellationTokenSource();

// Act
var task = host.RunAsyncCore(cts.Token);
var task = host.RunAsyncCore(cts.Token, cultureProvider);

cts.Cancel();
await task.TimeoutAfter(TimeSpan.FromSeconds(3));
Expand All @@ -41,10 +41,10 @@ public async Task RunAsync_CallingTwiceCausesException()
// Arrange
var builder = new WebAssemblyHostBuilder(new TestJSUnmarshalledRuntime());
var host = builder.Build();
host.CultureProvider = new TestSatelliteResourcesLoader();
var cultureProvider = new TestSatelliteResourcesLoader();

var cts = new CancellationTokenSource();
var task = host.RunAsyncCore(cts.Token);
var task = host.RunAsyncCore(cts.Token, cultureProvider);

// Act
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => host.RunAsyncCore(cts.Token));
Expand All @@ -63,7 +63,7 @@ public async Task DisposeAsync_CanDisposeAfterCallingRunAsync()
var builder = new WebAssemblyHostBuilder(new TestJSUnmarshalledRuntime());
builder.Services.AddSingleton<DisposableService>();
var host = builder.Build();
host.CultureProvider = new TestSatelliteResourcesLoader();
var cultureProvider = new TestSatelliteResourcesLoader();

var disposable = host.Services.GetRequiredService<DisposableService>();

Expand All @@ -72,7 +72,7 @@ public async Task DisposeAsync_CanDisposeAfterCallingRunAsync()
// Act
await using (host)
{
var task = host.RunAsyncCore(cts.Token);
var task = host.RunAsyncCore(cts.Token, cultureProvider);

cts.Cancel();
await task.TimeoutAfter(TimeSpan.FromSeconds(3));
Expand Down