> ## Documentation Index
> Fetch the complete documentation index at: https://easyaf.dev/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

### <Icon icon="hammer" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> .ctor

Creates a new instance of the [JsModule](/blazoressentials/api-reference/CloudNimble/BlazorEssentials/JsModule) 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".

### <Icon icon="hammer" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> .ctor

Creates a new instance of the [JsModule](/blazoressentials/api-reference/CloudNimble/BlazorEssentials/JsModule) 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.

### <Icon icon="hammer" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> .ctor <Badge color="gray">Inherited</Badge>

<Note>Inherited from `object`</Note>

#### Syntax

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

## Properties

### <Icon icon="tag" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> 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

### <Icon icon="function" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> DisposeAsync

Disposes of

#### Syntax

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

#### Returns

Type: `System.Threading.Tasks.ValueTask`

### <Icon icon="code-fork" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> Equals <Badge color="gray">Inherited</Badge> <Badge color="orange">Virtual</Badge>

<Note>Inherited from `object`</Note>

#### Syntax

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

#### Parameters

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

#### Returns

Type: `bool`

### <Icon icon="thumbtack" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> Equals <Badge color="gray">Inherited</Badge>

<Note>Inherited from `object`</Note>

#### Syntax

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

#### Parameters

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

#### Returns

Type: `bool`

### <Icon icon="code-fork" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> GetHashCode <Badge color="gray">Inherited</Badge> <Badge color="orange">Virtual</Badge>

<Note>Inherited from `object`</Note>

#### Syntax

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

#### Returns

Type: `int`

### <Icon icon="function" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> GetType <Badge color="gray">Inherited</Badge>

<Note>Inherited from `object`</Note>

#### Syntax

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

#### Returns

Type: `System.Type`

### <Icon icon="function" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> 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` -

### <Icon icon="function" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> 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` -

### <Icon icon="function" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> 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` -

### <Icon icon="function" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> MemberwiseClone <Badge color="gray">Inherited</Badge>

<Note>Inherited from `object`</Note>

#### Syntax

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

#### Returns

Type: `object`

### <Icon icon="thumbtack" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> ReferenceEquals <Badge color="gray">Inherited</Badge>

<Note>Inherited from `object`</Note>

#### Syntax

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

#### Parameters

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

#### Returns

Type: `bool`

### <Icon icon="code-fork" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> ToString <Badge color="gray">Inherited</Badge> <Badge color="orange">Virtual</Badge>

<Note>Inherited from `object`</Note>

#### Syntax

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

#### Returns

Type: `string?`

## Related APIs

* Microsoft.JSInterop.IJSObjectReference
* System.IAsyncDisposable
