I have a .NET Standard project that includes a bunch of models and methods, and I want to use them in a NodeJS application written in TypeScript. All the samples I see for Blazor JavaScript interop integrate with JS through Razor files, but I couldn't find any samples that show how to integrate .NET code with NodeJS. Is this possible at all and if yes, how? Thanks!
1 Answer
This is not possible Client-side Blazor works only in browser and interop is only with browser JS, since it is browser who run WASM and JS inside themselves.
Previously you can theoretically integrate some NodeJS inside ASP.NET Core application using NodeServices, but they are would be obsolete in .NET Core 3. See https://github.com/aspnet/AspNetCore/issues/12890
If you want to run some code from Blazor inside NodeJS likely you have to create separate command line application and communicate between it and your NodeJS application.
4 Comments
codevision
In more details, Client Side Blazor is Mono which executes the C# DLLs. So likely you can make Client Side Blazor run inside NodeJS, but what it gives to you? You will run Mono inside WASM. To call some C# code, you likely has to either write some additional C# code to run it inside Mono WASM, and at that point you can just run C# code under Mono/.NET Core and communicate somehow with NodeJS. Client Side Blazor in its current state does not designed for your use-case.
Stefan Over
@orad With what @codevision said, that would mean you need to ship the Mono environment (compiled to WASM), all the DLLs required (including all the system stuff) on your own. When building the client-side blazor app, the
bin\Debug\netstandard2.0\dist folder will hold all required files, including the DLLs, as well as the Mono runtime as WASM.DaNeSh
This is not Blazor but you can run C# inside NodeJS github.com/ncave/dna-redux