-
Notifications
You must be signed in to change notification settings - Fork 686
Add primitive Files resource to Aspire.Hosting #11276
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: mitchdenny <[email protected]>
@copilot remove the list of files on the Also add a |
🚀 Dogfood this PR with: curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 11276 Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 11276" |
1 similar comment
🚀 Dogfood this PR with: curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 11276 Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 11276" |
…nd replace WithFile/WithFiles with WithSource Co-authored-by: mitchdenny <[email protected]>
I've made the requested changes in commit 8d99ff3:
The API is now simplified to: builder.AddFiles("static-content").WithSource("content"); |
@copilot when |
Co-authored-by: mitchdenny <[email protected]>
I've implemented the requested event-driven architecture in commit 5dcaf5c. When
Invalid directories log warnings but don't fail the resource initialization. All existing tests continue to pass. |
This PR implements a new primitive Files resource in the Aspire project, providing a standardized way to manage file collections within the Aspire application model.
Overview
The Files resource introduces a lightweight primitive for representing and managing collections of files in Aspire applications. This is useful for scenarios where applications need to track configuration files, templates, assets, or other file-based resources.
Implementation Details
Core Components
IResourceWithFiles Interface
IEnumerable<string>
for file path accessFilesResource Class
Resource
IResourceWithFiles
andIResourceWithoutLifetime
AddFile()
andAddFiles()
methodsFilesProducedEvent
IDistributedApplicationResourceEvent
for consistencyBuilder Extensions
AddFiles()
method that creates an empty files resourceWithSource()
method for adding source paths to the resourceWithSource()
now wires up to theOnResourceInitialize
event for directory validation and event firingEvent Handling
When
WithSource(...)
is called, it:FilesSourceAnnotation
to track the source pathDuring resource initialization, the event handler:
FilesProducedEvent
with all valid files found in directoriesResourceReadyEvent
to signal the resource is readyUsage Examples
Playground Application
A complete playground application is included at
playground/files/
that demonstrates the Files resource usage:Files.AppHost
project with proper configurationAddFiles("static-content").WithSource("../content")
to reference a content directoryindex.html
file that explains the Files resource functionalityTesting
Comprehensive test suite includes:
WithSource()
methodBenefits
IResourceWithoutLifetime
)AddFiles()
andWithSource()
methodsThis primitive resource provides a foundation for file-based scenarios in Aspire applications while maintaining consistency with the existing resource model.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.