Skip to content

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.

Terminal window
dotnet new install Granit.Templates

To verify the installation:

Terminal window
dotnet new list granit

You should see three templates: granit-api, granit-api-full, and granit-module.

A lightweight API project with the essential Granit modules: Core, Timing, Persistence, Security, and Observability.

Terminal window
dotnet new granit-api -n MyApp

What gets generated:

  • Program.cs with the Granit host builder
  • AppModule.cs declaring module dependencies
  • appsettings.json with default configuration

Best for: learning Granit, prototyping, and small microservices where you want to pick additional modules yourself.

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.cs
  • Program.cs configures the Granit host, loads modules, and starts the application.
  • AppModule.cs declares which Granit modules your application depends on using [DependsOn(typeof(...))] attributes.
  • appsettings.json contains connection strings, observability settings, and module configuration with sensible defaults.
  • AppModuleTests.cs verifies that the module graph resolves correctly and the application starts without errors.

All templates accept standard dotnet new parameters. The most commonly used:

ParameterDescriptionDefault
-nProject name and root namespaceGranitApp
-oOutput directoryCurrent directory
--frameworkTarget frameworknet10.0

With your project scaffolded, continue to the next page to explore the documentation and find the guides most relevant to your use case.

Next Steps