https://github.com/ktsu-dev/imguiprovider
A dependency injection abstraction layer over ImGui implementations for .NET.
https://github.com/ktsu-dev/imguiprovider
abstraction backend-abstraction csharp dear-imgui dependency-injection dotnet hexa-net imgui-provider provider-pattern rendering windowing
Last synced: 11 days ago
JSON representation
A dependency injection abstraction layer over ImGui implementations for .NET.
- Host: GitHub
- URL: https://github.com/ktsu-dev/imguiprovider
- Owner: ktsu-dev
- License: mit
- Created: 2025-07-23T21:32:29.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2026-06-15T19:48:02.000Z (23 days ago)
- Last Synced: 2026-06-15T21:24:07.033Z (23 days ago)
- Topics: abstraction, backend-abstraction, csharp, dear-imgui, dependency-injection, dotnet, hexa-net, imgui-provider, provider-pattern, rendering, windowing
- Language: C#
- Homepage: https://ktsu.dev
- Size: 196 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
- Authors: AUTHORS.md
- Copyright: COPYRIGHT.md
Awesome Lists containing this project
README
# ImGuiProvider
A dependency injection abstraction layer over ImGui implementations for .NET, providing clean interfaces and swappable backends.
## Features
- **Dependency Injection** - Clean integration with `Microsoft.Extensions.DependencyInjection`
- **Provider Abstraction** - `IImGuiProvider` interface wrapping 160+ ImGui methods allows swapping implementations
- **Backend Support** - Separate `IPlatformBackend` and `IRendererBackend` interfaces for windowing and rendering
- **Context Management** - `ImGuiContext` handles the full frame lifecycle (initialize, begin frame, end frame, dispose)
- **Built-in Implementation** - Ships with `HexaNetImGuiProvider` wrapping Hexa.NET.ImGui
## Installation
```bash
dotnet add package ktsu.ImGuiProvider
```
## Quick Start
```csharp
using ImGuiProvider.Extensions;
using ImGuiProvider.Services;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddImGui(); // Registers HexaNetImGuiProvider as singleton
var serviceProvider = services.BuildServiceProvider();
var context = serviceProvider.GetRequiredService();
```
## Usage with Backends
```csharp
var services = new ServiceCollection();
services.AddImGui();
services.AddImGuiBackend();
services.AddImGuiBackend();
var serviceProvider = services.BuildServiceProvider();
var context = serviceProvider.GetRequiredService();
// Resolve and attach backends
var platformBackend = serviceProvider.GetRequiredService();
var rendererBackend = serviceProvider.GetRequiredService();
context.Initialize();
context.AddBackend(platformBackend);
context.AddBackend(rendererBackend);
context.InitializeBackends();
// Render loop
while (running)
{
context.BeginFrame();
// Your ImGui code here
var provider = serviceProvider.GetRequiredService();
provider.ShowDemoWindow();
context.EndFrame();
}
context.Dispose();
```
## Custom Implementations
### Custom Provider
```csharp
public class MyProvider : IImGuiProvider
{
// Implement all IImGuiProvider methods
}
services.AddImGui();
// Or with a factory:
services.AddImGui(sp => new MyProvider());
```
### Custom Backend
```csharp
public class MyBackend : IRendererBackend
{
public string Name => "My Backend";
public bool Initialize() => true;
public void Shutdown() { }
public void NewFrame() { }
public void RenderDrawData(nint drawData) { }
public void SetCurrentContext(nint context) { }
public bool CreateDeviceObjects() => true;
public void InvalidateDeviceObjects() { }
public void Dispose() { }
}
services.AddImGuiBackend();
```
## Requirements
- .NET 8.0, 9.0, or 10.0
- Hexa.NET.ImGui 2.2.8.4
- Microsoft.Extensions.DependencyInjection.Abstractions 9.0.7
## License
MIT License