File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed
src/ProjectTemplates/Web.ProjectTemplates/content/RazorClassLibrary-CSharp Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -13,24 +13,27 @@ namespace Company.RazorClassLibrary1
1313
1414 public class ExampleJsInterop : IAsyncDisposable
1515 {
16- private readonly Task < IJSObjectReference > moduleTask ;
16+ private readonly Lazy < Task < IJSObjectReference > > moduleTask ;
1717
1818 public ExampleJsInterop ( IJSRuntime jsRuntime )
1919 {
20- moduleTask = jsRuntime . InvokeAsync < IJSObjectReference > (
21- "import" , "./_content/Company.RazorClassLibrary1/exampleJsInterop.js" ) . AsTask ( ) ;
20+ moduleTask = new ( async ( ) => await jsRuntime . InvokeAsync < IJSObjectReference > (
21+ "import" , "./_content/Company.RazorClassLibrary1/exampleJsInterop.js" ) ) ;
2222 }
2323
2424 public async ValueTask < string > Prompt ( string message )
2525 {
26- var module = await moduleTask ;
26+ var module = await moduleTask . Value ;
2727 return await module . InvokeAsync < string > ( "showPrompt" , message ) ;
2828 }
2929
3030 public async ValueTask DisposeAsync ( )
3131 {
32- var module = await moduleTask ;
33- await module . DisposeAsync ( ) ;
32+ if ( moduleTask . IsValueCreated )
33+ {
34+ var module = await moduleTask . Value ;
35+ await module . DisposeAsync ( ) ;
36+ }
3437 }
3538 }
3639}
You can’t perform that action at this time.
0 commit comments