dotnet / aspire

An opinionated, cloud ready stack for building observable, production ready, distributed applications in .NET
https://learn.microsoft.com/dotnet/aspire
MIT License
3.65k stars 416 forks source link

Validation of resources and annotations #1769

Open JamesNK opened 8 months ago

JamesNK commented 8 months ago

The app model doesn't have a good validation story.

Resources and annotations are stored as loose collections:

There is no centralized validation of values in these collections. Problems:

For example, duplicate route names are not allowed. The AddProject/AddContainer/AddExecutable methods are checking for duplicate names but it's possible to add resources directly to the app model collection. There is duplicate validation in the Build() method to check again for duplicates.

The same issue exists with endpoints on a resource. A resource shouldn't have endpoints with duplicate names. There is validation in builder methods, but it's still possible to add a duplicate endpoint directly to the annotation.

There are also annotations that should have a maximum of one instance, e.g. ManifestPublishingCallbackAnnotation.

mitchdenny commented 7 months ago

For the last one I started to add some loose validation in my recent changes to the Redis resource. I think we may need to start to have different kinds of annotations, (singletons etc) which also have static methods defined on their interfaces for set validation etc.