Skip to content
Public template

About

Modular .NET solution template for building scalable microservices with clean architecture

Topics

Resources

Stars

20 stars

Watchers

1 watching

Forks

Latest commit

 

History

40 Commits

Folders and files

Repository files navigation

ModularNet

Unit Tests Code Coverage XERJ Corpus Hub contributor

ModularNet Architecture

Introduction

ModularNet is a layered, modular architecture for building maintainable and testable .NET applications (.NET 10). It enforces a strict separation of concerns through interface-based communication and Dependency Injection across five layers (Api, Business, Domain, Infrastructure, and Shared), keeping all business logic isolated from API entry points and external infrastructure.

This repository also serves as a ready-to-use template featuring:

  • User registration and authentication with Google Firebase
  • Token validation and scope-based authorization
  • Transactional email sending via Azure Communication Services
  • Secrets management via Azure Key Vault
  • In-memory and Redis caching
  • Structured logging and auditing with Serilog and MySQL
  • Unit of Work pattern coordinating atomic Dapper transactions across repositories

Architecture & Coding Standards

All architectural rules, layer responsibilities, differences from Onion Architecture, naming conventions, testing practices, and feature implementation guidelines are documented in Coding Standards.

Tech Stack & Dependencies

  • Framework: .NET 10 (ASP.NET Core Web API)
  • Authentication: Firebase Admin SDK & JWT Bearer Authentication
  • Authorization: Microsoft.Identity.Web ([Authorize] and [RequiredScope])
  • Database: MySQL (MySqlConnector, Dapper, Unit of Work pattern, schema in database/database_schema.sql)
  • Caching: In-Memory cache & Azure Cache for Redis (StackExchange.Redis)
  • Emailing: Azure Communication Services Email (Azure.Communication.Email)
  • Secrets Management: Azure Key Vault (Azure.Security.KeyVault.Secrets & Azure.Identity)
  • Logging & Telemetry: Serilog & Azure Application Insights
  • Testing: xUnit & Moq (ModularNet.UnitTests and ModularNet.IntegrationTests)

Documentation & Community

  • Coding Standards: Architecture rules, conventions, and step-by-step feature guide.
  • Wiki: Component-by-component reference for the solution.
  • Discussions: Ideas, questions, and feedback. Contributions and Pull Requests are welcome!

Multiple infrastructure implementations

Define a shared Infrastructure interface for interchangeable implementations, register each with a distinct dependency-injection key, and select the implementation in its corresponding manager. Other managers access it through that manager's interface. Add a new implementation by registering a new key and updating the manager's selection logic.

For example, CacheManager selects keyed ICacheRepository adapters for memory or Redis. UsersManager chooses a backend through ICacheManager using its CacheType constant; GetUserFirstNameByUserId caches a name for five minutes. Invalidate the key when names change, or choose an acceptable expiration.

MemoryCacheEnabled and RedisCacheEnabled control operations, not registrations. A disabled cache returns misses and ignores writes and removals; it does not fall back. Redis needs its connection configuration when enabled. For value types, a miss returns default, indistinguishable from a cached default value.

Database implementations also need provider-specific SQL, connections, and transaction handling. Repositories in one unit of work must share a scoped connection and transaction. Test each provider against its database; keyed registration alone does not provide cross-provider transactions.

About

Modular .NET solution template for building scalable microservices with clean architecture

Topics

Resources

Stars

20 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages