AI + .NET Integration Guide

Add AI to Your .NET Application

AI features are no longer optional for competitive software — clients are asking for them in every project. This page covers the architecture, tools, and C# code patterns for integrating Azure OpenAI and Semantic Kernel into real Blazor and ASP.NET Core apps.

The live demo below isn't a mockup — it's a working AI assistant running directly inside this portfolio, built with the exact same patterns described here.

Live Demo

This is a real AI integration — not a chatbot script. Ask it anything about .NET + AI. It demonstrates exactly what can be embedded in your Blazor or ASP.NET Core application.

AI Integration Assistant

Live demo — powered by Claude AI

Ask me anything about AI + .NET

This demo shows how AI chat can be embedded in any Blazor or ASP.NET Core app

Powered by Claude AI · Rate-limited to prevent abuse · Your messages are not stored

The Shift

Why .NET + AI is the biggest opportunity right now

Clients are asking — every project

In the last year, 'can you add AI to this?' has become the most common question in .NET project discussions. Businesses that can't answer yes are losing contracts.

The .NET ecosystem is AI-ready today

Microsoft's Semantic Kernel SDK is production-stable, Azure OpenAI is enterprise-compliant, and Blazor's real-time model is ideal for streaming AI responses.

Your existing C# codebase is the advantage

You don't rebuild your app. Semantic Kernel integrates as an injectable service — your business logic, database, and APIs stay exactly as they are. AI is added on top.

Most .NET developers aren't doing it yet

This creates a clear window. Early adopters — developers who can confidently architect .NET + AI solutions — command significantly higher rates and more interesting projects.

Architecture

How it fits into your .NET app

The pattern is the same regardless of whether you're building a new Blazor app or adding AI to an existing ASP.NET Core project.

Typical .NET AI Integration Architecture

Blazor UI

Component

ChatService

C# Injectable

Semantic Kernel

Orchestrator

Azure OpenAI

GPT-4o / Embed.

⬆ Vector DB / Memory (optional)
Code Patterns

Real C# implementation

1. Set up Semantic Kernel in Program.cs

Register Semantic Kernel as a singleton service — it becomes injectable throughout your entire Blazor or ASP.NET Core app.

// 1. Install packages
// dotnet add package Microsoft.SemanticKernel
// dotnet add package Microsoft.SemanticKernel.Connectors.OpenAI

// 2. Program.cs — register Semantic Kernel
builder.Services.AddSingleton(sp =>
{
    var kernel = Kernel.CreateBuilder()
        .AddAzureOpenAIChatCompletion(
            deploymentName: "gpt-4o",
            endpoint:       builder.Configuration["AzureOpenAI:Endpoint"]!,
            apiKey:         builder.Configuration["AzureOpenAI:ApiKey"]!
        )
        .Build();
    return kernel;
});

2. ChatService — your AI conversation layer

An injectable C# service that manages conversation history and calls the AI model. Clean separation from your UI.

// ChatService.cs — injectable service for Blazor components
public class ChatService(Kernel kernel)
{
    private readonly List<ChatMessageContent> _history = [];

    public async Task<string> SendMessageAsync(string userMessage)
    {
        _history.Add(new ChatMessageContent(AuthorRole.User, userMessage));

        var chat = kernel.GetRequiredService<IChatCompletionService>();
        var settings = new OpenAIPromptExecutionSettings
        {
            MaxTokens   = 500,
            Temperature = 0.7
        };

        var response = await chat.GetChatMessageContentAsync(
            chatHistory: new ChatHistory(_history),
            executionSettings: settings,
            kernel: kernel
        );

        _history.Add(response);
        return response.Content ?? string.Empty;
    }
}

3. Blazor component — drop-in chat UI

A Razor component that injects ChatService and handles user input. This is the same pattern used by the live demo above.

@* ChatWidget.razor — drop this anywhere in your Blazor app *@
@inject ChatService Chat

<div class="chat-container">
    @foreach (var msg in _messages)
    {
        <div class="message @(msg.IsUser ? "user" : "assistant")">
            @msg.Content
        </div>
    }

    <div class="input-row">
        <input @bind="_input" @onkeydown="HandleKey"
               placeholder="Ask anything..." />
        <button @onclick="Send" disabled="@_loading">
            @(_loading ? "Thinking..." : "Send")
        </button>
    </div>
</div>

@code {
    private string _input  = "";
    private bool   _loading = false;
    private List<(string Content, bool IsUser)> _messages = [];

    private async Task Send()
    {
        if (string.IsNullOrWhiteSpace(_input)) return;
        _messages.Add((_input, true));
        var prompt = _input;
        _input   = "";
        _loading = true;
        var reply = await Chat.SendMessageAsync(prompt);
        _messages.Add((reply, false));
        _loading = false;
    }

    private async Task HandleKey(KeyboardEventArgs e)
    {
        if (e.Key == "Enter") await Send();
    }
}

4. RAG pattern — AI that knows your business data

Retrieval-Augmented Generation lets the AI answer from your own documents, policies, or product data — not just general knowledge.

// RAG (Retrieval-Augmented Generation) — add your own data
// 1. Store your documents as embeddings
var memory = kernel.GetRequiredService<ISemanticTextMemory>();

await memory.SaveInformationAsync(
    collection: "product-docs",
    text:       "Our return policy allows returns within 30 days...",
    id:         "policy-001"
);

// 2. Retrieve relevant context before answering
var results = memory.SearchAsync("product-docs", userQuestion, limit: 3);
var context = string.Join("\n", await results.Select(r => r.Metadata.Text).ToListAsync());

// 3. Inject context into the prompt
var prompt = $"""
    Answer based only on this context:
    {context}

    Question: {userQuestion}
""";
Tech Stack

The recommended toolchain

Microsoft

Semantic Kernel

Orchestration layer — connects your .NET app to AI models, memory, and plugins

Microsoft

Azure OpenAI

Enterprise AI models (GPT-4o, text-embedding-3) with data privacy, no training on your data

OpenAI

OpenAI API

Direct OpenAI access — simpler for smaller projects, no Azure setup required

Open Source

Qdrant / pgvector

Vector database for semantic search and RAG — stores AI embeddings alongside your SQL data

Microsoft

Blazor Server/WASM

Renders the AI chat UI in real-time — SignalR connection shows streaming tokens as they arrive

Open Source

Hangfire

Runs AI processing jobs in the background — batch embedding, scheduled summarisation, async pipelines

Use Cases

What clients are asking for

These are the AI feature requests that come up most often in .NET project discussions right now.

AI Customer Support Chat

Replace FAQ pages with a chat widget that answers from your actual documentation. Blazor + Semantic Kernel + your PDF/Word knowledge base.

Smart Data Extraction

Users upload invoices, contracts, or forms — AI extracts structured data automatically into your MS-SQL database. No manual entry.

Intelligent Report Generator

AI reads your database, understands context, and generates human-readable reports or summaries on demand. Works in WPF dashboards too.

AI-Assisted Code Review

Internal developer tool: paste a C# function, get an AI review with security, performance, and style feedback — all within your .NET tooling.

Process Automation Agent

AI that reads emails, classifies them, and triggers business workflows in your existing ASP.NET Core app — no manual routing.

Semantic Search

Go beyond keyword search — let users find records, documents, or products by meaning. Embedding-based search over your existing SQL data.

Want AI features in your .NET app?

The architecture above is exactly how I approach AI integration projects. If you have an existing .NET application and want to add AI features — or you're building something new with AI at the core — let's talk.