> ## Documentation Index
> Fetch the complete documentation index at: https://easyaf.nimbleapps.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# JsModule

> A wrapper that makes it easier to dynamically import JavaScript modules in Blazor. Can be used as the foundation              to build strongly-typed .NET wr...

## Definition

**Assembly:** CloudNimble.BlazorEssentials.dll

**Namespace:** CloudNimble.BlazorEssentials

**Inheritance:** System.Object

## Syntax

```csharp theme={"dark"}
CloudNimble.BlazorEssentials.JsModule
```

## 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

### &#x20;.ctor

Creates a new instance of the [JsModule](https://easyaf.nimbleapps.cloud/blazoressentials/api-reference/CloudNimble/BlazorEssentials/JsModule.md) class.

#### Syntax

```csharp theme={"dark"}
public JsModule(Microsoft.JSInterop.IJSRuntime jsRuntime, string modulePath = "")
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `jsRuntime` | `Microsoft.JSInterop.IJSRuntime` | The [IJSRuntime](https://learn.microsoft.com/dotnet/api/microsoft.jsinterop.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/{packageName}/{pathFromWwwRoot}.js". |

#### Remarks

If you don't provide a *modulePath*, the constructor will attempt to infer it from the calling
assembly, in the format "../\_content/{callingAssemblyName}/{callingAssemblyName}.js".

### &#x20;.ctor

Creates a new instance of the [JsModule](https://easyaf.nimbleapps.cloud/blazoressentials/api-reference/CloudNimble/BlazorEssentials/JsModule.md) class.

#### Syntax

```csharp theme={"dark"}
public JsModule(Microsoft.JSInterop.IJSRuntime jsRuntime, string packageName, string modulePath)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `jsRuntime` | `Microsoft.JSInterop.IJSRuntime` | The [IJSRuntime](https://learn.microsoft.com/dotnet/api/microsoft.jsinterop.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.

### &#x20;.ctor Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public Object()
```

## Properties

### &#x20;Instance

Returns a [Lazy`1](https://learn.microsoft.com/dotnet/api/system.lazy-1) reference to the [Task`1](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1) of importing the module through
[IJSRuntime](https://learn.microsoft.com/dotnet/api/microsoft.jsinterop.ijsruntime).

#### Syntax

```csharp theme={"dark"}
public System.Lazy<System.Threading.Tasks.Task<Microsoft.JSInterop.IJSObjectReference>> Instance { get; private set; }
```

#### Property Value

Type: `System.Lazy<System.Threading.Tasks.Task<Microsoft.JSInterop.IJSObjectReference>>`

#### Remarks

We're using [Lazy`1](https://learn.microsoft.com/dotnet/api/system.lazy-1) here to ensure that the module is imported exactly once and only when needed.             [Lazy`1](https://learn.microsoft.com/dotnet/api/system.lazy-1) manages the instance for us

## Methods

### &#x20;DisposeAsync

Disposes of

#### Syntax

```csharp theme={"dark"}
public System.Threading.Tasks.ValueTask DisposeAsync()
```

#### Returns

Type: `System.Threading.Tasks.ValueTask`

### &#x20;Equals Inherited Virtual

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public virtual bool Equals(object obj)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `obj` | `object?` | - |

#### Returns

Type: `bool`

### &#x20;Equals Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public static bool Equals(object objA, object objB)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `objA` | `object?` | - |
| `objB` | `object?` | - |

#### Returns

Type: `bool`

### &#x20;GetHashCode Inherited Virtual

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public virtual int GetHashCode()
```

#### Returns

Type: `int`

### &#x20;GetType Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public System.Type GetType()
```

#### Returns

Type: `System.Type`

### &#x20;InvokeAsync

#### Syntax

```csharp theme={"dark"}
public System.Threading.Tasks.ValueTask<TValue> InvokeAsync<TValue>(string identifier, object[] args = null)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `identifier` | `string` | - |
| `args` | `object?[]?` | - |

#### Returns

Type: `System.Threading.Tasks.ValueTask<TValue>`

#### Type Parameters

* `TValue` -

### &#x20;InvokeAsync

#### Syntax

```csharp theme={"dark"}
public System.Threading.Tasks.ValueTask<TValue> InvokeAsync<TValue>(string identifier, System.Threading.CancellationToken cancellationToken, object[] args = null)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `identifier` | `string` | - |
| `cancellationToken` | `System.Threading.CancellationToken` | - |
| `args` | `object?[]?` | - |

#### Returns

Type: `System.Threading.Tasks.ValueTask<TValue>`

#### Type Parameters

* `TValue` -

### &#x20;InvokeAsync

#### Syntax

```csharp theme={"dark"}
public System.Threading.Tasks.ValueTask<TValue> InvokeAsync<TValue>(string identifier, System.TimeSpan timeout, object[] args = null)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `identifier` | `string` | - |
| `timeout` | `System.TimeSpan` | - |
| `args` | `object?[]?` | - |

#### Returns

Type: `System.Threading.Tasks.ValueTask<TValue>`

#### Type Parameters

* `TValue` -

### &#x20;MemberwiseClone Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
protected internal object MemberwiseClone()
```

#### Returns

Type: `object`

### &#x20;ReferenceEquals Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public static bool ReferenceEquals(object objA, object objB)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `objA` | `object?` | - |
| `objB` | `object?` | - |

#### Returns

Type: `bool`

### &#x20;ToString Inherited Virtual

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public virtual string ToString()
```

#### Returns

Type: `string?`

## Related APIs

* Microsoft.JSInterop.IJSObjectReference
* System.IAsyncDisposable


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.