Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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 (7 months ago)
- Default Branch: main
- Last Pushed: 2024-09-29T22:39:43.000Z (4 months ago)
- Last Synced: 2024-09-30T07:20:59.820Z (4 months ago)
- Topics: async, blazor, csharp, dotnet, import, module, moduleimport, moduleimportutil, parallel, util, utils
- Language: C#
- Homepage: https://soenneker.com
- Size: 457 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[![](https://img.shields.io/nuget/v/soenneker.blazor.utils.moduleimport.svg?style=for-the-badge)](https://www.nuget.org/packages/soenneker.blazor.utils.moduleimport/)
[![](https://img.shields.io/github/actions/workflow/status/soenneker/soenneker.blazor.utils.moduleimport/publish-package.yml?style=for-the-badge)](https://github.com/soenneker/soenneker.blazor.utils.moduleimport/actions/workflows/publish-package.yml)
[![](https://img.shields.io/nuget/dt/soenneker.blazor.utils.moduleimport.svg?style=for-the-badge)](https://www.nuget.org/packages/soenneker.blazor.utils.moduleimport/)# ![](https://user-images.githubusercontent.com/4441470/224455560-91ed3ee7-f510-4041-a8d2-3fc093025112.png) 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");
}
}
```