Shared Projects : Overview
The Shared layer (Shared Kernel in DDD terminology) contains code that is shared across all Bounded Contexts. It provides base classes, abstractions, and cross-cutting concerns that are not specific to any single Bounded Context.
Shared projects are generated once per solution and are referenced by all Source projects depending on the target layer or presentation technology.
Some Shared projects can depend on other Shared projects but none depend on your Source projects. It can easily be extended and reused across different Solutions and even be extracted as a separate library or NuGet package.
Required Shared projects
Some Shared projects are always generated to support the solution architecture :
- Shared.Core
- Shared.Domain
- Shared.Application
- Shared.Infrastructure.Persistence
Conditional Shared projects
Some Shared projects are only generated when specific presentation types are selected :
- Shared.Presentation : Generated if any Bounded Context has any presentation (Blazor Server, Blazor WebAssembly, or Minimal API)
- Shared.Presentation.Blazor : Generated if any Bounded Context has a Blazor Server or Blazor WebAssembly presentation
- Shared.Presentation.BlazorServer : Generated if any Bounded Context has a Blazor Server presentation
- Shared.Presentation.BlazorWebAssembly : Generated if any Bounded Context has a Blazor WebAssembly presentation
- Shared.Presentation.MinimalApi : Generated if any Bounded Context has a Minimal API or Blazor WebAssembly presentation
Project Dependencies
The shared projects are designed with specific dependency chains and external NuGet packages in mind :
- Shared.Core : No dependencies, uses FluentValidation, Microsoft.Extensions.Localization, Microsoft.Extensions.Options.ConfigurationExtensions
- Shared.Domain : No dependencies, uses no external packages
- Shared.Application : Depends on Shared.Core, Shared.Domain, uses no external packages
- Shared.Infrastructure.Persistence : Depends on Shared.Domain, Shared.Application, uses Microsoft.EntityFrameworkCore.SqlServer, Microsoft.EntityFrameworkCore.Tools, Microsoft.Extensions.Configuration.EnvironmentVariables, Microsoft.Extensions.Configuration.Json
- Shared.Presentation : Depends on Shared.Core, uses Microsoft.Extensions.Localization, Serilog.AspNetCore
- Shared.Presentation.Blazor : Depends on Shared.Core, uses MudBlazor, MudBlazor.Translations
- Shared.Presentation.BlazorServer : No dependencies, uses Microsoft.AspNetCore.App
- Shared.Presentation.BlazorWebAssembly : Depends on Shared.Core, uses FluentValidation, Microsoft.AspNetCore.Components.WebAssembly, Microsoft.Extensions.Http, Microsoft.Extensions.Localization, Serilog.Extensions.Hosting, Serilog.Settings.Configuration, Serilog.Sinks.Console
- Shared.Presentation.MinimalApi : Depends on Shared.Core, uses Microsoft.AspNetCore.OpenApi, Microsoft.OpenApi, Scalar.AspNetCore