Project Templates
Granit ships dotnet new templates that scaffold fully configured projects in seconds.
Each template wires up the module system, dependency injection, and configuration so you
can focus on your domain logic.
Install the templates
Section titled “Install the templates”dotnet new install Granit.TemplatesTo verify the installation:
dotnet new list granitYou should see three templates: granit-api, granit-api-full, and granit-module.
Choose a template
Section titled “Choose a template”A lightweight API project with the essential Granit modules: Core, Timing, Persistence, Security, and Observability.
dotnet new granit-api -n MyAppWhat gets generated:
Program.cswith the Granit host builderAppModule.csdeclaring module dependenciesappsettings.jsonwith default configuration
Best for: learning Granit, prototyping, and small microservices where you want to pick additional modules yourself.
Everything in granit-api, plus MultiTenancy, Caching, Notifications, BackgroundJobs,
and Localization pre-configured and ready to run.
dotnet new granit-api-full -n MyAppWhat gets generated:
- Full API project with all production modules wired
- Docker Compose with PostgreSQL, Redis, and Keycloak
- Health checks and readiness probes
- Keycloak realm configuration
Best for: production SaaS applications that need tenant isolation, background processing, and notification delivery from day one.
Creates a reusable Granit module package following the isolated DbContext pattern and standard project structure.
dotnet new granit-module -n MyCompany.BillingWhat gets generated:
- Module class with
[DependsOn]attributes - Tests project with xUnit, Shouldly, and NSubstitute
- README with package documentation
Best for: extracting shared business logic into a distributable NuGet package that other Granit applications can consume.
Project structure
Section titled “Project structure”Running dotnet new granit-api -n MyApp produces the following layout:
MyApp/├── src/MyApp.Api/│ ├── Program.cs│ ├── AppModule.cs│ ├── appsettings.json│ └── appsettings.Development.json└── tests/MyApp.Api.Tests/ └── AppModuleTests.csProgram.csconfigures the Granit host, loads modules, and starts the application.AppModule.csdeclares which Granit modules your application depends on using[DependsOn(typeof(...))]attributes.appsettings.jsoncontains connection strings, observability settings, and module configuration with sensible defaults.AppModuleTests.csverifies that the module graph resolves correctly and the application starts without errors.
Template parameters
Section titled “Template parameters”All templates accept standard dotnet new parameters. The most commonly used:
| Parameter | Description | Default |
|---|---|---|
-n | Project name and root namespace | GranitApp |
-o | Output directory | Current directory |
--framework | Target framework | net10.0 |
What to read next
Section titled “What to read next”With your project scaffolded, continue to the next page to explore the documentation and find the guides most relevant to your use case.