https://github.com/soenneker/soenneker.blazor.utils.moduleimport
A Blazor utility library assisting with asynchronous module loading
https://github.com/soenneker/soenneker.blazor.utils.moduleimport
async blazor csharp dotnet import module moduleimport moduleimportutil parallel util utils
Last synced: 3 months ago
JSON representation
A Blazor utility library assisting with asynchronous module loading
- Host: GitHub
- URL: https://github.com/soenneker/soenneker.blazor.utils.moduleimport
- Owner: soenneker
- License: mit
- Created: 2024-06-23T21:47:09.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-08T23:59:03.000Z (3 months ago)
- Last Synced: 2025-04-09T00:07:25.115Z (3 months ago)
- Topics: async, blazor, csharp, dotnet, import, module, moduleimport, moduleimportutil, parallel, util, utils
- Language: C#
- Homepage: https://soenneker.com
- Size: 1.56 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.nuget.org/packages/soenneker.blazor.utils.moduleimport/)
[](https://github.com/soenneker/soenneker.blazor.utils.moduleimport/actions/workflows/publish-package.yml)
[](https://www.nuget.org/packages/soenneker.blazor.utils.moduleimport/)#  Soenneker.Blazor.Utils.ModuleImport
### A Blazor utility library assisting with asynchronous module loadingThis library simplifies the process of loading JavaScript modules and provides methods for waiting until a module is loaded and disposing of modules when they are no longer needed.
## Features
- Import JavaScript modules dynamically.
- Wait until a module is fully loaded.
- Dispose of JavaScript modules when they are no longer needed.
- Singleton pattern to ensure that each module is loaded only once.## Installation
To install, add the package to your Blazor project using the .NET CLI:
```sh
dotnet add package Soenneker.Blazor.Utils.ModuleImport
```Register it in DI:
```csharp
builder.Services.AddModuleImportUtil();
```### Example
Here's an example of how to use the `ModuleImportUtil` in a Blazor component:
```csharp
@page "/example"
@inject IModuleImportUtil ModuleImportUtil
@implements IAsyncDisposableModule Import Example
Load Module
@code {
private async Task LoadModule()
{
var module = await ModuleImportUtil.Import("exampleModule");
await ModuleImportUtil.WaitUntilLoaded("exampleModule");// Guaranteed that the module has been added to the DOM, and available at this point
}public async ValueTask DisposeAsync()
{
await ModuleImportUtil.DisposeModule("exampleModule");
}
}
```