How jgmelon22/studentsnhibernatedemo works
Project Type and Purpose
• This is a server-side .NET layered API project (“NHibernate Students API”) built to demonstrate DDD and the Mediator pattern using NHibernate as the ORM against a SQL Server database.
• No UI layer; it exposes HTTP endpoints (Swagger/OpenAPI) for CRUD operations on a Student aggregate.
High-Level File Structure and Architectural Layers
• Presentation/API Layer (src/NHibernateDemo.API)
• HTTP endpoints (StudentEndpoint.cs)
• Middleware (BasicAuthMiddleware)
• Swagger setup, DI configuration (IocExtensions, SwaggerCollection)
• Application Layer (src/NHibernateDemo.Application)
• Commands & Queries + their Handlers (CreateStudentCommandHandler, GetStudentsQueryHandler, etc.)
• Implements the Mediator pattern (NetDevPack.SimpleMediator)
• Domain/Core Layer (src/NHibernateDemo.Core)
• Entities (Student)
• DTOs (StudentRequest, StudentResponse)
• Mapping extensions, shared Result type
• Infrastructure Layer (src/NHibernateDemo.Infrastructure)
• NHibernate configuration & Fluent mappings (StudentMap)
• Repository interfaces & implementations (IStudentRepository → StudentRepository)
• Database connectivity configuration (BasicAuthOptions, NHibernateConfiguration)
• Database (/SQL/CreateDatabaseScript.sql)
• SQL Server schema creation
• Unit Tests (/tests/UnitTests)
• Layer-specific tests (API endpoints, middleware, application commands/queries)
Main Components and Their Relationships
• API (ASP.NET Core)
→ Invokes Application via Mediator (commands/queries)
• Application
→ Depends on Core for DTOs/entities
→ Depends on Infrastructure via repository interfaces
• Infrastructure
→ Implements repository interfaces using NHibernate & FluentNHibernate
→ Connects to SQL Server
• Database (SQL Server)
← Receives generated SQL from NHibernate sessions
• Middleware (BasicAuth) sits in the pipeline before controllers
• Swagger exposes the HTTP contract
Architectural Patterns and Design Principles
• Layered (Clean) Architecture: clear boundaries between API, Application, Domain, Infrastructure
• Mediator Pattern: decouples controllers from business logic via commands & queries
• Dependency Injection: appsettings.json + IocExtensions register services at startup
• Domain-Driven Design (DDD): Entities/mappings in Core, repositories in Infrastructure
• Separation of Concerns: No data-access code in controllers, no HTTP code in domain