Skip to the content.

Architecture

S#arp Architecture enforces a strict Domain-Driven Design layering, using project references to make the dependency direction hard to violate by accident:

Domain

The Domain layer is where business entities and business logic live. It should stay persistence-ignorant: SharpArch.Domain has no infrastructure dependencies of its own. It does, however, define the persistence-support interfacesIRepository<TEntity,TId>, ILinqRepository<TEntity,TId>, ITransactionManager, IEntityDuplicateChecker — that the domain depends on but does not implement. This inversion is what keeps domain and application code ORM-agnostic.

Building blocks provided here:

Additional occupants that typically live alongside the domain layer:

Prior to version 4, S#arp Architecture shipped a dedicated Tasks layer for non-persistence application services. As of v4 there is no built-in Tasks layer — use a library such as MediatR for commands, queries, and event/command handlers instead.

Infrastructure

The Infrastructure layer wires up NHibernate: session factory configuration, Fluent NHibernate mappings, and dependency injection registration (SharpArch.NHibernate, SharpArch.NHibernate.DependencyInjection). You can extend the provided repository implementations with additional query methods, but it’s recommended to write your own query/specification objects instead of growing a generic repository without bound.

Presentation

The Presentation layer is an ASP.NET Core project — MVC, Web API, or Blazor — containing controllers/endpoints, view models, and application startup/composition (SharpArch.Web.AspNetCore provides the [Transaction] attribute and AutoTransactionHandler MVC filter described in Unit of Work).

Additional occupants:

Tests

SharpArch.Testing, SharpArch.Testing.Xunit[.NHibernate], and SharpArch.Testing.NUnit provide base classes — e.g. RepositoryTestsBase / TransientDatabaseTests — that spin up a throwaway database per test, so repository and mapping tests don’t need a shared test database.

See Src/Samples/TardisBank for an end-to-end reference that ties all four layers together.