Definition
Assembly: CloudNimble.BlazorEssentials.dll Namespace: CloudNimble.BlazorEssentials Inheritance: System.ObjectSyntax
Summary
A wrapper that makes it easier to dynamically import JavaScript modules in Blazor. Can be used as the foundation to build strongly-typed .NET wrappers around JavaScript libraries.Remarks
I built this because trying to remember the same pattern for importing JS modules in Blazor was driving me nuts.Constructors
.ctor
Creates a new instance of the JsModule class.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
jsRuntime | Microsoft.JSInterop.IJSRuntime | The IJSRuntime instance that was likely injected by the ViewModel / Page / Control this module is |
| being used in. | ||
modulePath | string | The full path to the JS file to wrap. Should usually be in the format ”../content//.js”. |
Remarks
If you don’t provide a modulePath, the constructor will attempt to infer it from the calling assembly, in the format ”../_content//.js”..ctor
Creates a new instance of the JsModule class.Syntax
Parameters
| Name | Type | Description |
|---|---|---|
jsRuntime | Microsoft.JSInterop.IJSRuntime | The IJSRuntime instance that was likely injected by the ViewModel / Page / Control this module is |
| being used in. | ||
packageName | string | - |
modulePath | string | The path to the file, usually from the ‘wwwroot’ folder in the base of the project. |
Remarks
The SDK-style project system actually does a really good job of knowing when the PackageId is different from the AssemblyName, so this constructor may not be necessary..ctor Inherited
Inherited from
objectSyntax
Properties
Instance
Returns a Lazy1](https://learn.microsoft.com/dotnet/api/system.lazy-1) reference to the [Task1 of importing the module through
IJSRuntime.
Syntax
Property Value
Type:System.Lazy<System.Threading.Tasks.Task<Microsoft.JSInterop.IJSObjectReference>>
Remarks
We’re using Lazy1](https://learn.microsoft.com/dotnet/api/system.lazy-1) here to ensure that the module is imported exactly once and only when needed. [Lazy1 manages the instance for us
Methods
DisposeAsync
Disposes ofSyntax
Returns
Type:System.Threading.Tasks.ValueTask
Equals Inherited Virtual
Inherited from
objectSyntax
Parameters
| Name | Type | Description |
|---|---|---|
obj | object? | - |
Returns
Type:bool
Equals Inherited
Inherited from
objectSyntax
Parameters
| Name | Type | Description |
|---|---|---|
objA | object? | - |
objB | object? | - |
Returns
Type:bool
GetHashCode Inherited Virtual
Inherited from
objectSyntax
Returns
Type:int
GetType Inherited
Inherited from
objectSyntax
Returns
Type:System.Type
InvokeAsync
Syntax
Parameters
| Name | Type | Description |
|---|---|---|
identifier | string | - |
args | object?[]? | - |
Returns
Type:System.Threading.Tasks.ValueTask<TValue>
Type Parameters
TValue-
InvokeAsync
Syntax
Parameters
| Name | Type | Description |
|---|---|---|
identifier | string | - |
cancellationToken | System.Threading.CancellationToken | - |
args | object?[]? | - |
Returns
Type:System.Threading.Tasks.ValueTask<TValue>
Type Parameters
TValue-
InvokeAsync
Syntax
Parameters
| Name | Type | Description |
|---|---|---|
identifier | string | - |
timeout | System.TimeSpan | - |
args | object?[]? | - |
Returns
Type:System.Threading.Tasks.ValueTask<TValue>
Type Parameters
TValue-
MemberwiseClone Inherited
Inherited from
objectSyntax
Returns
Type:object
ReferenceEquals Inherited
Inherited from
objectSyntax
Parameters
| Name | Type | Description |
|---|---|---|
objA | object? | - |
objB | object? | - |
Returns
Type:bool
ToString Inherited Virtual
Inherited from
objectSyntax
Returns
Type:string?
Related APIs
- Microsoft.JSInterop.IJSObjectReference
- System.IAsyncDisposable