AgentSkillsCN

overview-drn-framework

DRN.Framework架构概览——包层级结构(SharedKernel → Utils → Testing/EntityFramework → Hosting)、依赖关系、核心约定以及框架理念。若想全面了解框架的整体结构,可从这里入手。关键词:框架、架构、概览、包层级、约定、框架理念、DRN框架、包依赖、技能、DRN、领域、设计、共享、内核、工具类、托管、实体、框架、测试

SKILL.md
--- frontmatter
name: overview-drn-framework
description: DRN.Framework architecture overview - Package hierarchy (SharedKernel → Utils → Testing/EntityFramework → Hosting), dependency relationships, core conventions, and framework philosophy. Start here for understanding the overall framework structure. Keywords: framework, architecture, overview, package-hierarchy, conventions, framework-philosophy, drn-framework, package-dependencies, skills, drn, domain, design, shared, kernel, utils, hosting, entity, framework, testing

DRN.Framework Overview

Architecture overview of DRN.Framework—a convention-based .NET framework for distributed reliable applications.

When to Apply

  • Understanding framework architecture and design principles
  • Deciding which package to use for a specific need
  • Learning core conventions shared across all packages
  • Extending or contributing to framework packages

Framework Stack

code
┌─────────────────────────────────────────────────────────────────┐
│                     DRN.Framework Stack                         │
├─────────────────────────────────────────────────────────────────┤
│  DRN.Framework.Hosting      │  Web hosting, security, endpoints │
│  DRN.Framework.Testing      │  Test contexts, containers        │
│  DRN.Framework.EntityFramework │ DbContext, migrations, IDs     │
│  DRN.Framework.Jobs         │  Background job scheduling        │
│  DRN.Framework.MassTransit  │  Message bus integration          │
├─────────────────────────────────────────────────────────────────┤
│  DRN.Framework.Utils        │  DI, settings, logging, IDs       │
├─────────────────────────────────────────────────────────────────┤
│  DRN.Framework.SharedKernel │  Domain, exceptions, JSON         │
└─────────────────────────────────────────────────────────────────┘

Package Purposes

PackagePurposeKey Features
SharedKernelLightweight domain primitivesSourceKnownEntity, AggregateRoot, DomainEvent, Exceptions, JsonConventions
UtilsCore utilitiesAttribute DI, IAppSettings, HybridCache, Logging, Extensions
HostingWeb application hostingDrnProgramBase, Security, Endpoints, Middlewares
EntityFrameworkDatabase accessDrnContext, Conventions, Auto-migrations
TestingTest infrastructureDrnTestContext, Containers, DataAttributes, FlurlHttpTest
JobsBackground jobsJob scheduling (Hangfire-like)
MassTransitMessagingMessage bus integration

Core Conventions

1. Attribute-Based Dependency Injection

All DRN projects use attribute-based service registration:

csharp
[Scoped<IMyService>]
public class MyService : IMyService { }

// Registration in module:
services.AddServicesWithAttributes();
AttributeLifetime
[Singleton<T>]Singleton
[Scoped<T>]Scoped
[Transient<T>]Transient
[Config("Section")]Configuration binding
[HostedService]Background service

See: drn-utils.md

2. Configuration Layering

Configuration applied in order:

  1. appsettings.json
  2. appsettings.{Environment}.json
  3. User secrets (development)
  4. Environment variables
  5. Mounted settings (/appconfig/)
  6. Command line arguments

3. JSON Conventions

System.Text.Json defaults overridden globally:

  • JsonSerializerDefaults.Web
  • JsonStringEnumConverter
  • AllowTrailingCommas = true
  • PropertyNameCaseInsensitive = true
  • CamelCase naming

4. Exception Handling

DRN exceptions map to HTTP status codes:

ExceptionStatus
ValidationException400
UnauthorizedException401
ForbiddenException403
NotFoundException404
ConflictException409
ConfigurationException500
csharp
throw ExceptionFor.NotFound("User not found");

Package Dependency Graph

mermaid
graph LR
    H[Hosting] --> U[Utils]
    EF[EntityFramework] --> U
    U --> SK[SharedKernel]
    T[Testing] --> H
    T --> EF

Key Points:

  • SharedKernel has NO dependencies (can be used in Contract layers)
  • Utils provides core infrastructure
  • Hosting/EntityFramework are peer packages
  • Testing depends on everything for integration tests

Module Pattern

Each assembly exposes a module for service registration:

csharp
public static class InfraModule
{
    public static IServiceCollection AddSampleInfraServices(this IServiceCollection sc)
    {
        sc.AddServicesWithAttributes();
        return sc;
    }
}

Reliability Characteristics

DRN Framework ensures:

  • Secure - Security headers, CSP, host filtering
  • Observable - Structured logging, scoped logs
  • Maintainable - Convention over configuration
  • Performant - Optimized defaults
  • Scalable - Distributed ID generation
  • Self-documenting - Endpoint metadata

Related Skills

SkillPackage
drn-domain-design.mdIdentity, Entities, Repositories
drn-sharedkernel.mdDomain primitives, exceptions
drn-utils.mdDI, settings, logging
drn-hosting.mdWeb hosting, security
drn-entityframework.mdDatabase access
drn-testing.mdTest infrastructure