|
1 | | -## Coding Style |
| 1 | +## .NET Aspire Community Toolkit — Copilot Coding Instructions |
2 | 2 |
|
3 | | -- Use spaces for indentation with four-spaces per level, unless it is a csproj file, then use two-spaces per level. |
4 | | -- For integrations use the following namespace rules: |
5 | | - - If the integration is a hosting integration (starts with CommunityToolkit.Aspire.Hosting), extension methods should be placed in `Aspire.Hosting`. |
6 | | - - If the integration is a client integration (starts with CommunityToolkit.Aspire), extension methods should be placed in `Microsoft.Extensions.Hosting`. |
| 3 | +### Project Overview |
| 4 | + |
| 5 | +- This repo is a collection of community-driven integrations and extensions for [.NET Aspire](https://aka.ms/dotnet/aspire), supporting a wide range of runtimes and cloud-native patterns. |
| 6 | +- Major components are organized by integration in `src/`, with tests in `tests/` and usage examples in `examples/`. |
| 7 | +- Each integration is a NuGet package, following naming: `CommunityToolkit.Aspire.Hosting.*` (hosting) or `CommunityToolkit.Aspire.*` (client). |
| 8 | + |
| 9 | +### Architecture & Patterns |
| 10 | + |
| 11 | +- **Resource-based model:** Integrations define resources (e.g., `NodeAppResource`, `NpmInstallerResource`) that appear in the Aspire dashboard and support parent-child relationships for startup ordering and dependency management. |
| 12 | +- **Extension methods:** |
| 13 | + - Hosting integrations: extension methods in `Aspire.Hosting` namespace. |
| 14 | + - Client integrations: extension methods in `Microsoft.Extensions.Hosting` namespace. |
7 | 15 | - Use file-scoped namespaces. |
8 | | -- All public members require doc comments. |
9 | | -- Prefer type declarations over `var` when the type isn't obvious. |
10 | | -- Use the C# Collection Initializer syntax, `List<T> items = []` (where `List<T>` could be any collection type), rather than `new()`. |
11 | | -- Use `is not null` or `is null` over `!= null` and `== null`. |
| 16 | +- **Installer resources:** For Node.js, package installers (npm/yarn/pnpm) are modeled as `ExecutableResource` instances, providing dashboard visibility and proper process management. See `src/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions/REFACTORING_NOTES.md` for rationale and migration. |
| 17 | + |
| 18 | +### Coding Style |
12 | 19 |
|
13 | | -## Sample hosting integration |
| 20 | +- Use spaces for indentation (4 per level; 2 for `.csproj`). |
| 21 | +- All public members require XML doc comments. |
| 22 | +- Prefer explicit type declarations unless type is obvious. |
| 23 | +- Use collection initializers: `List<T> items = []`. |
| 24 | +- Use `is not null`/`is null` over `!= null`/`== null`. |
| 25 | + |
| 26 | +#### Example: Hosting Integration |
14 | 27 |
|
15 | 28 | ```csharp |
16 | 29 | namespace Aspire.Hosting; |
17 | 30 |
|
18 | 31 | public static class SomeProgramExtensions |
19 | 32 | { |
| 33 | + /// <summary>Adds a SomeProgram resource.</summary> |
20 | 34 | public static IResourceBuilder<SomeProgramResource> AddSomeProgram( |
21 | 35 | this IDistributedApplicationBuilder builder, |
22 | 36 | [ResourceName] string name) |
23 | 37 | { |
24 | | - var resource = new SomeProgramResource(name); |
| 38 | + SomeProgramResource resource = new(name); |
25 | 39 | return builder.AddResource(resource); |
26 | 40 | } |
27 | 41 | } |
28 | 42 | ``` |
| 43 | + |
| 44 | +### Developer Workflows |
| 45 | + |
| 46 | +- **Build:** Use `dotnet build` or VS Code task `build`. |
| 47 | +- **Test:** |
| 48 | + - All tests use xUnit. Place test projects in `tests/` (naming: `CommunityToolkit.Aspire.Hosting.MyIntegration.Tests`). |
| 49 | + - Integration tests that test containerized resources will require Docker; mark with `[RequiresDocker]` if so. |
| 50 | + - Use `WaitForTextAsync` to wait for resource readiness if not using Aspire health checks. |
| 51 | + - Add new test projects to CI by running `./eng/testing/generate-test-list-for-workflow.sh` and updating `.github/workflows/tests.yml`. |
| 52 | +- **Debug:** For devcontainers, manually forward DCP ports if HTTP endpoints are unreachable. |
| 53 | + |
| 54 | +### Project Conventions |
| 55 | + |
| 56 | +- Integrations must add `Aspire.Hosting` as a dependency; see `Directory.Build.props` for shared MSBuild config. |
| 57 | +- Use the [create-integration guide](../docs/create-integration.md) for new integrations. |
| 58 | +- For Azure/Dapr integrations, see `src/Shared/DaprAzureExtensions/README.md` for shared resource patterns. |
| 59 | + |
| 60 | +### External Dependencies & Integration |
| 61 | + |
| 62 | +- Many integrations wrap external services (e.g., Dapr, MinIO, k6, Node.js, Python, Rust, Java, etc.). |
| 63 | +- Each integration's README in `src/` or `examples/` details usage, supported versions, and special setup. |
| 64 | +- For Node.js, package manager flags can be customized via extension methods (see `src/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions/README.md`). |
| 65 | + |
| 66 | +### Documentation & Contribution |
| 67 | + |
| 68 | +- Main docs: [Microsoft Docs](https://learn.microsoft.com/dotnet/aspire/community-toolkit/overview) |
| 69 | +- FAQ: `docs/faq.md` | Contribution: `CONTRIBUTING.md` |
| 70 | +- Versioning: `docs/versioning.md` | Diagnostics: `docs/diagnostics.md` |
| 71 | + |
| 72 | +--- |
| 73 | + |
| 74 | +If you find any unclear or incomplete sections, please provide feedback to improve these instructions. |
0 commit comments