1
votes

Context:

We want to create an inhouse Blazor Library for our Blazor-WA projects. The Blazor Library contains template components which can be consumed by all of our other Blazor projects.

Some components in the Blazor Library are merged with JavaScript. Therefore we want to use the JS-Interop which is provided by Blazor.

Approach:

The ASP.NET Core Razor components class libraries (RCL) seem to be a suitable approach to create an Blazor Library. We have created an Blazor Library called BlazorLib which is now implemented via RCL. The Blazor WebAssembyly Project called BlazorLib-dev consumes the library BlazorLib. Here is the Structure:

enter image description here

Problem:

RCL seem not to provide JavaScript Interop:

enter image description here

Question:

What is the correct approach to create an Blazor Library including JS-Interop, which can be consumed by any second Blazor-WA project?

1

1 Answers

0
votes

Try using the full namespace:

@inject Microsoft.JSInterop.IJSRuntime

You can also import the namespace in your _Imports.razor file

@using Microsoft.JSInterop