|
|
5 years ago | |
|---|---|---|
| .. | ||
| Microsoft.JSInterop | 5 years ago | |
| Microsoft.JSInterop.JS | 5 years ago | |
| JSInterop.slnf | 5 years ago | |
| README.md | 5 years ago | |
| startvs.cmd | 6 years ago | |
This directory contains sources for Microsoft.JSInterop, a package that provides abstractions and features for interop between .NET and JavaScript code.
The primary use case is for applications built with Blazor. For usage information, see the following documentation:
This section provides a brief overview of the architecture.
Microsoft.JSInterop is a .NET package with the following roles:
IJSRuntime, IJSInProcessRuntime, DotNetObjectReference, IJSObjectReference, and others.JSRuntime and JSObjectReference. These implement common logic around handling errors and asynchrony, even though they are independent of any particular runtime environment.IJSRuntime that simplify making calls with differing numbers of parameters, cancellation tokens, and other characteristics.For these types to become usable in a particular runtime environment, such as Blazor Server or Blazor WebAssembly, the runtime environment implements its own concrete subclasses that know how to dispatch calls to the actual JavaScript runtime that is available in that environment. For example, Blazor Server uses the SignalR-based circuit to send invocations to the end user's browser.
Microsoft.JSInterop.JS is the JavaScript-side counterpart to the preceding. It runs within a standard web browser environment, receives the invocations from .NET code, executes them, and sends back results in the format understood by the JSRuntime base class. This includes special handling for certain parameter types such as ElementReference and DotNetObjectReference. Microsoft.JSInterop.JS also exposes JavaScript functions that can be used to issue calls from JavaScript to .NET.
Since Microsoft.JSInterop.JS is platform-independent, runtime environments such as Blazor Server or Blazor WebAssembly must initialize it by registering environment-specific callbacks that know how to dispatch invocations across their own communication channels.
To build the .NET code, you can:
dotnet build in the Microsoft.JSInterop/src directory. You can also read more on building a subset of the code.dotnet build or dotnet test in the Microsoft.JSInterop/test directory. You can also read more about how to run the tests on the command line.Alternatively, open JSInterop.slnf in Visual Studio.
To build the JavaScript code, execute the following commands in a command shell:
cd Microsoft.JSInterop.JS/srcnpm run precleannpm run buildWarning: Due to special requirements related to ASP.NET Core's CI process for Linux distributions, we store the compiled JavaScript artifacts for Microsoft.JSInterop.JS in source control in the Microsoft.JSInterop.JS/src/dist directory. If you edit and build JavaScript sources, your Git client should indicate that those outputs have changed. You will need to include changes to those dist files in any PRs that you submit. When this leads to merge conflicts, we have to resolve them manually by rebasing and rebuilding.
For more information, see the ASP.NET Core README.