# MIDCON.PluginUi.Abstractions

Abstractions layer for Blazor-based UI components in **MIDCON MCM plugin packages**.

Provides base classes and interfaces that plugin developers implement when building
the UI portions of an MCM plugin — ensuring a consistent component model across all plugins.

---

## Installation

```bash
dotnet add package MIDCON.PluginUi.Abstractions
```

Or in your `.csproj`:

```xml
<PackageReference Include="MIDCON.PluginUi.Abstractions" Version="x.y.z" />
```

---

## Dependencies

| Package | Version | Purpose |
|---|---|---|
| `Microsoft.AspNetCore.Components` | 10.0.7 | Blazor component model (`ComponentBase`) |

Target framework: **net10.0**

---

## Usage

### PluginComponentBase

`PluginComponentBase` extends `ComponentBase` and adds a built-in loading-state
pattern for async operations. Inherit from it in your plugin's Blazor components:

```csharp
using MIDCON.PluginUi.Abstractions;

public class MyPluginComponent : PluginComponentBase
{
    private async Task OnButtonClick()
    {
        await RunWithProgressAsync(async () =>
        {
            // IsLoading is true here — show spinner in your markup
            await SomeService.DoWorkAsync();
        });
        // IsLoading is false again, StateHasChanged() was called automatically
    }
}
```

In your `.razor` file:

```razor
@inherits PluginComponentBase

@if (IsLoading)
{
    <div class="spinner" />
}
else
{
    <button @onclick="OnButtonClick">Start</button>
}
```

`RunWithProgressAsync` sets `IsLoading = true`, yields the WASM thread
(so progress indicators can render), runs your work, then sets `IsLoading = false`
and calls `StateHasChanged()` — even if an exception is thrown.

---

## Versioning

This package uses [GitVersion](https://gitversion.net/) via `GitVersion.MsBuild`.
The version is derived automatically from the git history and tags.

To create a release version, tag the commit:

```bash
git tag v1.0.0
dotnet pack -c Release
```

---

## Building & Packing

```bash
# Restore & build
dotnet build src/MIDCON.PluginUi.Abstractions.slnx -c Release

# Create NuGet package
dotnet pack src/MIDCON.PluginUi.Abstractions/MIDCON.PluginUi.Abstractions.csproj -c Release -o ./artifacts
```

The resulting `.nupkg` is in `./artifacts/`.

---

## License

MIT — see [LICENSE](LICENSE).

**Author:** MidConsulting  
**Company:** MidConsulting
