-
Notifications
You must be signed in to change notification settings - Fork 153
Add extensibility article on how to write non-container custom resources #3850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: IEvangelist <[email protected]>
…icles Co-authored-by: IEvangelist <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @copilot - this Program.cs
file alone will not work without .NET 10, instead you need to include a .csproj for the Aspire app host, and likely a solution (I prefer the .slnx format) that points to the hosting and app host projects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the missing .csproj file for the AppHost project and a .slnx solution file that references both projects. The AppHost now has proper project structure with .NET 9 target framework and latest Aspire package versions. (2fba711)
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Aspire.Hosting" Version="8.0.0" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the latest version.
<PackageReference Include="Aspire.Hosting" Version="8.0.0" /> | |
<PackageReference Include="Aspire.Hosting" Version="9.3.2" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use Aspire.Hosting version 9.3.1. (2fba711)
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use .NET 9.
<TargetFramework>net8.0</TargetFramework> | |
<TargetFramework>net9.0</TargetFramework> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated target framework to net9.0. (2fba711)
1. **Resource cleanup**: Always implement proper disposal in lifecycle hooks | ||
2. **Error handling**: Catch and log exceptions, update status appropriately | ||
3. **Status updates**: Provide meaningful status information to users | ||
4. **Performance**: Avoid blocking operations in lifecycle methods | ||
5. **Dependencies**: Use dependency injection for required services |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. **Resource cleanup**: Always implement proper disposal in lifecycle hooks | |
2. **Error handling**: Catch and log exceptions, update status appropriately | |
3. **Status updates**: Provide meaningful status information to users | |
4. **Performance**: Avoid blocking operations in lifecycle methods | |
5. **Dependencies**: Use dependency injection for required services | |
1. **Resource cleanup**: Always implement proper disposal in lifecycle hooks | |
1. **Error handling**: Catch and log exceptions, update status appropriately | |
1. **Status updates**: Provide meaningful status information to users | |
1. **Performance**: Avoid blocking operations in lifecycle methods | |
1. **Dependencies**: Use dependency injection for required services |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the numbered list formatting to use "1." for all items as per the style guide. (2fba711)
|
||
For more sophisticated dashboard integration, you can use: | ||
|
||
- **Status notifications**: Update resource state and properties in real-time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should include links to these features, and how to implement them. I think we do have docs on some of those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added links to health checks documentation and dashboard exploration guide in the advanced dashboard features section. (2fba711)
--- | ||
title: Create non-container custom resources | ||
description: Learn how to create custom .NET Aspire resources that don't rely on containers using lifecycle hooks and dashboard integration. | ||
ms.date: 06/18/2025 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ms.date: 06/18/2025 | |
ms.date: 06/25/2025 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated ms.date to 06/25/2025. (2fba711)
|
||
## Dashboard integration | ||
|
||
The resource integrates with the Aspire dashboard through: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of this, it's an opening statement that's terminated with the :
. I was expecting a diagram, bullet list, or something... it took me a bit to realize that it was intended to be the subsections. I'd prefer strong details about the dashboard integration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrote the dashboard integration section with stronger details about how non-container resources integrate with the dashboard, removed the colon-terminated opening statement, and provided more concrete information about the integration channels. (2fba711)
> [!div class="nextstepaction"] | ||
> [Create non-container custom resources](custom-non-container-resource.md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't consider this really a next step, it's more like an alternative approach. I'd consider removing this link here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the link to non-container custom resources from the next steps section as it's more of an alternative approach than a continuation. (2fba711)
The extension method automatically registers the lifecycle hook: | ||
|
||
```csharp | ||
public static IResourceBuilder<HttpProxyResource> AddHttpProxy( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code block should instead use the :::code
syntax instead to pull in the HttpProxyResourceBuilderExtensions.cs file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced the inline code block with :::code syntax to reference the HttpProxyResourceBuilderExtensions.cs file directly. (2fba711)
docs/toc.yml
Outdated
@@ -378,6 +378,9 @@ items: | |||
- name: Create hosting integrations | |||
displayName: resources,extensibility,hosting,integrations | |||
href: extensibility/custom-hosting-integration.md | |||
- name: Create non-container custom resources |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original three articles here were delivered as a set, continuing on the previous content. Adding this one here makes this set disjointed, instead it might be better to have this under the Custom resources area in the TOC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the non-container custom resources article to a new "Custom resources" section in the TOC, separating it from the original three custom integration articles to avoid making them disjointed. (2fba711)
…ove docs structure Co-authored-by: IEvangelist <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is invalid .slnx
syntax. If you're not familiar with it, here's an example from one of my personal projects to learn from:
<Solution>
<Folder Name="/playground/">
<Project Path="playground/ProfanityFilter.Api/ProfanityFilter.Api.csproj" />
<Project Path="playground/ProfanityFilter.AppHost/ProfanityFilter.AppHost.csproj" />
</Folder>
<Folder Name="/Solution Items/">
<File Path=".dockerignore" />
<File Path=".editorconfig" />
<File Path=".github/workflows/dogfood.yml" />
<File Path=".github/workflows/dotnet.yml" />
<File Path=".github/workflows/release-api.yml" />
<File Path=".github/workflows/release-nuget.yml" />
<File Path=".github/workflows/release.yml" />
<File Path="action.yml" />
<File Path="Directory.Build.props" />
<File Path="Directory.Packages.props" />
<File Path="global.json" />
<File Path="LICENSE" />
<File Path="README.md" />
</Folder>
<Folder Name="/src/">
<Project Path="src/ProfanityFilter.Action/ProfanityFilter.Action.csproj" />
<Project Path="src/ProfanityFilter.Client/ProfanityFilter.Client.csproj" />
<Project Path="src/ProfanityFilter.Common/ProfanityFilter.Common.csproj" />
<Project Path="src/ProfanityFilter.Hosting/ProfanityFilter.Hosting.csproj" />
<Project Path="src/ProfanityFilter.Services/ProfanityFilter.Services.csproj" />
<Project Path="src/ProfanityFilter.WebApi/ProfanityFilter.WebApi.csproj" />
</Folder>
<Folder Name="/tests/">
<Project Path="tests/ProfanityFilter.Action.Tests/ProfanityFilter.Action.Tests.csproj" />
<Project Path="tests/ProfanityFilter.Client.Tests/ProfanityFilter.Client.Tests.csproj" />
<Project Path="tests/ProfanityFilter.Common.Tests/ProfanityFilter.Common.Tests.csproj" />
<Project Path="tests/ProfanityFilter.Services.Tests/ProfanityFilter.Services.Tests.csproj" />
</Folder>
</Solution>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the .slnx file syntax by converting from invalid JSON format to proper XML format with ProjectReference elements. (192c993)
docs/toc.yml
Outdated
- name: Custom resources | ||
items: | ||
- name: Create non-container custom resources | ||
displayName: resources,extensibility,hosting,integrations,lifecycle,dashboard | ||
href: extensibility/custom-non-container-resource.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see why this is confusing, and I admit...I wasn't very clear. Let's instead move this under Dev-time orchestration node instead. It can be a top-level node under that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the custom resources section under the Dev-time orchestration node as a top-level item, after "Persist data using volumes". (192c993)
…section Co-authored-by: IEvangelist <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need complete sentences with proper punctuation for all bullet points.
<Project> | ||
<Sdk Name="Microsoft.Build.Traversal" /> | ||
<ProjectReference Include="HttpProxy.Hosting/HttpProxy.Hosting.csproj" /> | ||
<ProjectReference Include="HttpProxySample.AppHost/HttpProxySample.AppHost.csproj" /> | ||
</Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<Project> | |
<Sdk Name="Microsoft.Build.Traversal" /> | |
<ProjectReference Include="HttpProxy.Hosting/HttpProxy.Hosting.csproj" /> | |
<ProjectReference Include="HttpProxySample.AppHost/HttpProxySample.AppHost.csproj" /> | |
</Project> | |
<Solution> | |
<Folder Name="/src/"> | |
<Project Path="HttpProxy.Hosting/HttpProxy.Hosting.csproj" /> | |
<Project Path="HttpProxySample.AppHost/HttpProxySample.AppHost.csproj" /> | |
</Folder> | |
</Solution> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the .slnx syntax to use proper XML format with folder structure and project elements as suggested. (18f672b)
docs/toc.yml
Outdated
- name: Custom resources | ||
items: | ||
- name: Create non-container custom resources | ||
displayName: resources,extensibility,hosting,integrations,lifecycle,dashboard | ||
href: extensibility/custom-non-container-resource.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- name: Custom resources | |
items: | |
- name: Create non-container custom resources | |
displayName: resources,extensibility,hosting,integrations,lifecycle,dashboard | |
href: extensibility/custom-non-container-resource.md | |
- name: Create non-container custom resources | |
displayName: resources,extensibility,hosting,integrations,lifecycle,dashboard | |
href: extensibility/custom-non-container-resource.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the TOC entry formatting for the custom resources article as suggested. (18f672b)
docs/toc.yml
Outdated
@@ -373,6 +378,7 @@ items: | |||
- name: Aspire.Hosting API reference | |||
href: /dotnet/api/?term=Aspire.Hosting&view=dotnet-aspire-9.3&preserve-view=true | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the empty line from the TOC as suggested. (18f672b)
Co-authored-by: IEvangelist <[email protected]>
Fixed all bullet points to use complete sentences with proper punctuation throughout the document. (18f672b) |
This PR adds a new documentation article that explains how to create custom .NET Aspire resources that don't rely on containers, addressing the need for guidance on non-container extensibility patterns.
What's Added
docs/extensibility/custom-non-container-resource.md
- Comprehensive guide on creating non-container custom resourcesdocs/extensibility/snippets/HttpProxyResource/
Key Content
The article covers:
AddConnectionString()
orAddParameter()
IResource
,IResourceWithEndpoints
, and extension methodsIDistributedApplicationLifecycleHook
for startup/shutdown coordinationExample Usage
The implementation shows how to:
Fixes #792.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.
Internal previews