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

Populate JSRuntime.Current before invoking Startup.ConfigureServices #5664

Open
chanan opened this Issue Dec 4, 2018 · 6 comments

Comments

Projects
None yet
5 participants
@chanan

chanan commented Dec 4, 2018

I have a library project that needs to do some initialization is the host project's Startup.cs that includes using javascript. This used to work prior to the JS syntax change. Now, however, JSRuntime.Current is null. I created a reproduction of the problem here: https://github.com/chanan/JSRuntimeRepro

@enetstudio

This comment has been minimized.

enetstudio commented Dec 11, 2018

@chanan,
JSRuntime.Current is null because your custom code is executed before it has the chance to
be initialized... You should follow the execution of the Blazor initialization process to detect how you can insert your code. Perhaps you start with this: https://github.com/aspnet/Blazor/blob/3e062cdefe334be161c8c5f8b3df25283a2fb8d6/src/Microsoft.AspNetCore.Components.Browser/Hosting/WebAssemblyHostBuilder.cs

Hope this helps...

@chanan

This comment has been minimized.

chanan commented Dec 11, 2018

@enetstudio Thanks, I did use WebAssemblyHostBuilder as a workaround.

I am wondering if JSRuntime can be initialized prior to call to the IoC. If not, this ticket can be closed.

@enetstudio

This comment has been minimized.

enetstudio commented Dec 11, 2018

Yes, this is a question I'd love to know... Why do you call an issue a ticket ?

@chanan

This comment has been minimized.

chanan commented Dec 11, 2018

Force of habit, sorry.

@danroth27

This comment has been minimized.

Member

danroth27 commented Dec 12, 2018

@SteveSandersonMS Could you please answer this one?

@SteveSandersonMS

This comment has been minimized.

Member

SteveSandersonMS commented Dec 12, 2018

TBH I can't immediately think of anything that would strictly stop us from making JSRuntime.Current be initalized before the call to Startup's ConfigureServices method. It should be viable in both the server-side and client-side execution models, since AFAIK we already have a per-user JS runtime instance before invoking that. However if I'm mistaken and we're not in a per-user context by that stage then maybe that would be a reason not to do it.

I'll rename this issue to suggest that as a future enhancement.

@SteveSandersonMS SteveSandersonMS changed the title from JSRuntime.Current is null in Startup.cs to Populate JSRuntime.Current before invoking Startup.Configure Dec 12, 2018

@SteveSandersonMS SteveSandersonMS changed the title from Populate JSRuntime.Current before invoking Startup.Configure to Populate JSRuntime.Current before invoking Startup.ConfigureServices Dec 12, 2018

@aspnet-hello aspnet-hello transferred this issue from aspnet/Blazor Dec 17, 2018

@aspnet-hello aspnet-hello added this to the Backlog milestone Dec 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment