Documentation Index
Fetch the complete documentation index at: https://mintlify.com/masastack/MASA.Framework/llms.txt
Use this file to discover all available pages before exploring further.
Masa.Contrib.Development.DaprStarter removes the friction of running dapr run manually every time you start a service locally. It integrates with the ASP.NET Core hosted-service model so the Dapr sidecar process is automatically launched when your application starts and cleanly stopped when it shuts down — letting you focus on writing code rather than managing infrastructure processes.
Installation
Add the ASP.NET Core integration package to your project:How It Works
DaprStarter wires three collaborating abstractions together into the ASP.NET Core lifecycle:| Component | Responsibility |
|---|---|
IDaprProcess | Lifecycle contract — Start(), Stop(), Dispose() |
DaprBackgroundService | IHostedService that calls Start on app startup and Stop on shutdown |
IAppPortProvider | Resolves the port your ASP.NET Core app is listening on (auto-detected from Kestrel) |
DefaultAvailabilityPortProvider | Finds a free OS port for the Dapr HTTP and gRPC sidecar listeners |
CommandLineBuilder | Assembles the final dapr run … command from resolved options |
DaprEnvironmentProvider | Reads Dapr-related environment variables (e.g. DAPR_HTTP_PORT) to blend with code config |
DaprBackgroundService starts, it calls IDaprProcess.Start(). The process implementation asks CommandLineBuilder to produce the full dapr run invocation, spawns the child process, and monitors it for premature exits. On IHostApplicationLifetime.ApplicationStopping, Stop() is called and the sidecar is terminated gracefully.
Configuration Options
All options are surfaced throughDaprOptions:
| Option | Type | Description |
|---|---|---|
AppId | string | Dapr application ID used for service discovery |
AppPort | int? | Port your app listens on; auto-detected from Kestrel when omitted |
DaprHttpPort | int? | Dapr HTTP sidecar port (defaults to 3500 when unset) |
DaprGrpcPort | int? | Dapr gRPC sidecar port (defaults to 50001 when unset) |
ComponentPath | string? | Path to the folder containing Dapr component YAML files |
Config | string? | Path to a Dapr configuration YAML file |
EnableProfiling | bool | Passes --enable-profiling to the sidecar |
LogLevel | string? | Sidecar log level (debug, info, warn, error) |
Registration
Inline code configuration
AppPort is optional. When you omit it, IAppPortProvider inspects the Kestrel server addresses at startup and picks the first available HTTP port automatically.
Configuration file
You can drive all options fromappsettings.json (or environment-specific variants) instead of hardcoding them:
DaprOptions section automatically:
Port Auto-Detection
WhenAppPort is not provided, DaprStarter uses IAppPortProvider to resolve the Kestrel listening port at runtime. If Dapr’s own ports (DaprHttpPort, DaprGrpcPort) are also left unset, DefaultAvailabilityPortProvider scans for free ephemeral ports and assigns them — useful in environments where default ports may already be in use.
Development Workflow
With DaprStarter registered, your typicaldotnet run or IDE F5 launch is all that is needed:
dapr run command is logged at startup so you can inspect the exact flags being used:
Conditional Registration
To ensure DaprStarter never runs in production, guard the registration with an environment check:<PackageReference> for convenience while preventing any risk of accidental production use.