feat: Injectable MaIN instead of static class#135
Open
srebrek wants to merge 4 commits into
Open
Conversation
- Introduce IMaINHub (Scoped) as the primary API surface for web APIs and testable code.
- AIHub static facade retained as [Obsolete] for backward compatibility.
- Add MaINBootstrapper.Hub accessor for zero-config CLI usage.
- Migrates integration tests off AIHub static state.
Web API:
```cs
builder.Services.AddMaIN(builder.Configuration);
app.MapGet("/ask", async (IMaINHub hub) =>
await hub.Chat()
.WithModel(...)
.WithMessage("Hello")
.CompleteAsync());
```
Console:
```cs
MaINBootstrapper.Initialize();
await MaINBootstrapper.Hub.Chat()
.WithModel(...)
.WithMessage("Hello")
.CompleteAsync();
```
… using static AIHub
…uration is provided
MaINDotnet-Bot
approved these changes
Jun 9, 2026
MaINDotnet-Bot
left a comment
Collaborator
There was a problem hiding this comment.
The PR successfully introduces a DI-friendly IMaINHub, effectively removing static dependencies. Architecture is correct and the code follows the project's design. Approved.
| internal sealed class MaINHub( | ||
| IAIHubServices services, | ||
| MaINSettings settings, | ||
| IHttpClientFactory httpClientFactory) : IMaINHub |
Collaborator
There was a problem hiding this comment.
Good implementation of the new hub pattern. The DI registration and usage in E2E tests look solid. No functional issues found.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces
IMaINHubas an injectable, DI-friendly entry point for MaIN.NET, replacing the staticAIHubfacade as the primary API surface (User usage remains the same). Also removes internal dependency on the staticAIHubfromChatContextandAgentContextby injectingModelContextdirectly.Changes
IMaINHub(Transient) injectable interface withChat(),Agent(),Flow(),Model(),Mcp()factory methods.MaINBootstrapper.Hubaccessor for zero-config console scenarios.AIHubas[Obsolete]- retained for backward compatibility, will be removed in the future.ModelContextintoChatContextandAgentContextconstructors - removes last internal usages of staticAIHub.AIHubto instance-basedIMaINHub./car/colorendpoint).Pros
AddMaIN(),UseMaIN()and injectIMaINHubin controllers and services.Agent/ChatContext.FromExistingbut this is explained in Propositions) - existingAIHubcode still compiles (with deprecation warning).Usage
Web API:
Console:
Propositions
MaINBootstrappershould be renamed to better match its role as the zero-config entry point for console aplications. MaybeMaIN(if it does not conflict with any namespaces)? In that case the usage in the console aplication scenario would look like: