Skip to content
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

Loose objects with strong views #7251

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

davidfowl
Copy link
Member

@davidfowl davidfowl commented Jan 25, 2025

  • This fundamentally changes the resource model to be all in on annotations. Resources are a set of annotatations and strongly typed "views" can be modeled over those annotations. Each resource has a ResourceTypeAnnotation which stores the actual resource type. This means that runtime code should never use is or as for resource type checks but should instead use the new ResourceKind API to determine the type of the resource.
  • This enables cleanly switching between resource types while keeping the veneer of strong typing at the top level.

TODO:

  • Update tests

Issues found:

  • We still need to design resources intentionally when want the ability to apply thier configuration to another resource. e.g. RunAsContainer for AzureRedis -> Redis container. This is trivial to do with the change, but doesn't solve the we need to duplicate the logic to configure redis.
  • Identity, the identity of the underlying resource needs to be based on the annotation collection, not the object instance.

/// <returns></returns>
/// <exception cref="DistributedApplicationException"></exception>
/// <exception cref="InvalidOperationException"></exception>
public static IResourceBuilder<RedisResource> ApplyRedis(this IResourceBuilder<RedisResource> builder, int? port = null, Action<IResourceBuilder<RedisResource>>? configureContainer = null)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eerhardt I don't think this will be the final API shape but the idea here is to get the redis defaults applied to an existing builder.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't expect "normal" customers to call this method right? Maybe it shouldn't be an extension method so it doesn't clutter up the Intellisense for normal AppHost developers.

- This fundamentally changes the resource model to be all in on annotations. Resources are a set of annotatations and strongly typed "views" can be modeled over those annotations. Each resource has a ResourceTypeAnnotation which stores the actual resource type. This means that runtime code should never use is or as (though we can make as work) for resource type checks, but should instead use the new ResourceKind API.
- This enables cleanly switching between resource types while keeping the veneer of strong typing at the top level.
@davidfowl davidfowl force-pushed the davidfowl/polymorhpic-resources branch from 9af7689 to 0f09e8c Compare January 27, 2025 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants