# XiHan.Framework **Repository Path**: XiHanFun/XiHan.Framework ## Basic Information - **Project Name**: XiHan.Framework - **Description**: 快速、轻量、高效、用心的 .Net 现代模块化开发框架。曦寒懿(XiHanFun)开源生态的后端基座,拥有底座、组件、应用的完整生态。 - **Primary Language**: C# - **License**: MIT - **Default Branch**: main - **Homepage**: https://framework.docs.xihanfun.com - **GVP Project**: No ## Statistics - **Stars**: 42 - **Forks**: 22 - **Created**: 2024-08-14 - **Last Updated**: 2026-09-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: xihan, 模块化, 企业级, Csharp, 开发框架 ## README
XiHan.Framework

XiHan.Framework

A fast, lightweight, efficient and thoughtfully built modern modular framework for .NET

Built on .NET 10 · 66 modular components · [DependsOn] declarations · topologically sorted loading

English | 简体中文

GitHub Stars Gitee Stars GitCode Stars

.NET C# Modules NuGet Downloads

License Last Commit Commit Activity Issues Contributors Repo Size

Ask DeepWiki Docs QQ Group

XiHanFun%2FXiHan.Framework | Trendshift

## Overview XiHan.Framework is a modular backend framework for enterprise applications, designed for ASP.NET Core services in a decoupled frontend/backend setup. It prefers what .NET already provides over third-party libraries, and puts the emphasis on clear module boundaries, controlled dependencies and maintainable extension points. Modules declare their dependencies with the `[DependsOn]` attribute and are loaded in topological order; application services plus dynamic API conventions give every module the same way to expose its endpoints. ## Documentation | Destination | Contents | | --- | --- | | [Documentation site](https://framework.docs.xihanfun.com) | Full guides and per-package API docs for all 66 packages | | [Framework engineering notes](./framework/README.md) | Layered architecture, module catalog, directory layout, dependencies | | [Changelog](https://framework.docs.xihanfun.com/changelog) | Release notes and upgrade advisories | | [Contributing guide](./CONTRIBUTING.md) | Branch conventions, commit rules, local build and test | ## Design Principles - **Layered architecture** — follow clear layering, no circular dependencies - **Dependency inversion** — higher layers do not depend on lower ones; both depend on abstractions - **Single responsibility** — each package owns exactly one functional area - **Open/closed** — open for extension, closed for modification, customizable through interfaces and base classes - **.NET 10 first** — use the built-ins (DI, logging, serialization) and reach for third-party libraries only when necessary - **Performance** — built on .NET 10's high-performance features; AOT is out of scope (SqlSugar / Castle DynamicProxy, plus Newtonsoft.Json pulled in transitively by SqlSugar, are not trimming-compatible yet) ## Tech Stack | Category | Technology | | --- | --- | | Runtime | .NET | | Language | C# | | ORM | SqlSugarCore | | Logging | Serilog.AspNetCore | | Caching | Microsoft.Extensions.Caching.Hybrid + StackExchangeRedis | | AOP | Castle.Core (DynamicProxy) | | Cryptography | BouncyCastle.Cryptography | | Serialization | System.Text.Json (built-in) | | Templating | Scriban | | AI | Microsoft.Extensions.AI + Microsoft.Agents.AI + MCP | | HTTP resilience | Microsoft.Extensions.Http.Polly | | gRPC | Grpc.AspNetCore | | Realtime | ASP.NET Core SignalR | | API docs | Scalar.AspNetCore + Swashbuckle.AspNetCore | | IP geolocation | IP2Region.Net | | Notifications | MailKit + Telegram.Bot | | Search | Elastic.Clients.Elasticsearch | | Testing | xunit.v3 + Microsoft.Testing.Platform (with the CodeCoverage extension) | Exact versions live in the `PackageReference` entries under `framework/src`. ## Getting Started ### Install Install the modules you need from NuGet: ```bash # Core module dotnet add package XiHan.Framework.Core # Web API module (includes the full middleware pipeline) dotnet add package XiHan.Framework.Web.Api # API documentation module dotnet add package XiHan.Framework.Web.Docs # Data access module dotnet add package XiHan.Framework.Data ``` ### Define a Module Every module derives from `XiHanModule` and declares its dependencies with `[DependsOn]`: ```csharp using XiHan.Framework.Core.Modularity; using XiHan.Framework.Web.Api; using XiHan.Framework.Data; [DependsOn( typeof(XiHanWebApiModule), typeof(XiHanDataModule) )] public class MyAppModule : XiHanModule { public override Task ConfigureServicesAsync(ServiceConfigurationContext context) { // Register services return Task.CompletedTask; } public override Task OnApplicationInitializationAsync(ApplicationInitializationContext context) { // Initialize the application return Task.CompletedTask; } } ``` ### Bootstrap the Application ```csharp using XiHan.Framework.Core.Extensions.DependencyInjection; using XiHan.Framework.Web.Core.Extensions.DependencyInjection; var builder = WebApplication.CreateBuilder(args); await builder.AddApplicationAsync(); var app = builder.Build(); await app.InitializeApplicationAsync(); await app.RunAsync(); ``` ### Module Lifecycle Each module exposes 7 lifecycle hooks, executed in topological order: ```text Service registration Application initialization ┌──────────────────────┐ ┌────────────────────────────────┐ │ PreConfigureServices │ │ OnPreApplicationInitialization │ │ ConfigureServices │ → │ OnApplicationInitialization │ │ PostConfigureServices│ │ OnPostApplicationInitialization│ └──────────────────────┘ └────────────────────────────────┘ ↓ ┌────────────────────────────────┐ │ OnApplicationShutdown │ └────────────────────────────────┘ ``` ## NuGet Packages Every module is published to [NuGet.org](https://www.nuget.org/packages?q=XiHan.Framework); package names match project names: ```bash # Search all XiHan.Framework packages dotnet package search XiHan.Framework ``` | Common package | Purpose | | --- | --- | | `XiHan.Framework.Core` | Modularity core (required) | | `XiHan.Framework.Web.Api` | Full Web API middleware pipeline | | `XiHan.Framework.Web.Docs` | Scalar + Swagger documentation | | `XiHan.Framework.Data` | SqlSugar data access | | `XiHan.Framework.Caching` | HybridCache + Redis | | `XiHan.Framework.Authentication` | JWT / OAuth2 authentication | | `XiHan.Framework.Authorization` | RBAC authorization | | `XiHan.Framework.EventBus` | Event bus + outbox | | `XiHan.Framework.AI` | Microsoft.Extensions.AI + MCP | The full module catalog lives in the [framework engineering notes](./framework/README.md#module-catalog). ## Requirements | Dependency | Version | | --- | --- | | .NET SDK | 10.0+ | | C# | Latest | | Platforms | Windows / Linux / macOS | ## Ecosystem - [XiHan.Framework](https://github.com/XiHanFun/XiHan.Framework) - A fast, lightweight, efficient and thoughtfully built modern modular framework for .NET - [XiHan.UI](https://github.com/XiHanFun/XiHan.UI) - A fast, lightweight, efficient and thoughtfully built framework-agnostic headless UI component library - [XiHan.BasicApp](https://github.com/XiHanFun/XiHan.BasicApp) - A beautifully crafted general-purpose admin kernel built on .NET (XiHan.Framework) and TypeScript (XiHan.UI) ## Contributing Issues and pull requests are welcome — see the [contributing guide](./CONTRIBUTING.md). ## Acknowledgements In no particular order. | Project | Thanks for | | ------------------------------------------ | ------------------------------------------------- | | [Abp](https://github.com/abpframework/abp) | Inspiring parts of the architecture and design | | Other third-party dependencies | Being the foundation this project is built upon | ## Support & Sponsorship If this project helps your work, feel free to buy the author a coffee. Official sponsorship page: https://docs.xihanfun.com/cosmos/sponsor ## License Copyright (c) 2021-Present XiHanFun and contributors. Released under the MIT License — see [License](./LICENSE). The XiHan.Framework logo and name belong to the author; third-party dependencies and services are governed by their own licenses and terms. This project is provided for study and reference; the author assumes no liability for any use of the software.