docs-aspire icon indicating copy to clipboard operation
docs-aspire copied to clipboard

Add extensiblity article on how to write a non container based custom resource

Open davidfowl opened this issue 9 months ago • 7 comments

As an example:

https://anthonysimmon.com/referencing-external-docker-containers-dotnet-aspire-custom-resources/

It should show how to use lifecycle hooks, the ResourceNotificationService, and the ResourceLoggerService to push updates to the dashboard.

cc @asimmon @mitchdenny

davidfowl avatar Apr 30 '24 18:04 davidfowl

This article should cover, or link to some kind of meta conversation around whether it makes sense to write a custom resource which is not container based.

Consider Aspire as it exists today, all of our resources are either container based, cloud-based (with or without emulators) or core resource types such as parameters.

In many cases a custom resource which is not a container could quite possibly be a very thin wrapper around AddParameter and AddConnectionString. In the article we would need to articulate the reason why someone would want to go to the extra effort to build a custom resource type.

For example, lets say you were calling an Internet hosted API that you couldn't replicate locally. That would really just be a URL and potentially some kind of API key.

@davidfowl can you give an example of a custom resource that is not:

a) something that you would NOT run locally in a container. b) something that requires the features of dashboard updates c) something that wouldn't be just as easily served by AddConnectionString()

mitchdenny avatar May 03 '24 01:05 mitchdenny

My aspire YARP resource that runs in process!:

https://github.com/davidfowl/AspireYarp

davidfowl avatar May 03 '24 05:05 davidfowl

The resource linked in the article above shows logs from the running container which makes it better than using AddConnectionString IMO.

davidfowl avatar May 03 '24 05:05 davidfowl

Another example are the Azure and AWS resources.

davidfowl avatar May 03 '24 05:05 davidfowl

If this can help, at Workleap we've been using custom resources in three ways:

  1. To host YARP (similar to, but not exactly like, https://github.com/davidfowl/AspireYarp)
  2. To host a minimal API that forwards the developer's local Azure CLI credentials to any container that uses Azure Identity with RBAC-protected resources (similar to what we distributed as a Docker image)
  3. Expose long-lived Docker containers that are managed by Docker Compose

asimmon avatar May 03 '24 16:05 asimmon

@davidfowl - I like it, want me to put something together based on the YARP example or just create one that add the SmtpClient like with the MailDev example, but shows how to do so as a component?

IEvangelist avatar Jun 04 '24 00:06 IEvangelist

@IEvangelist This is low priority at the moment. We have more important stuff to document 😄. Lets let this sit for a bit.

The main thing we'd want to show here is usage of IDistribuedApplicationLifecycleHook, ResourceLoggerService and ResoruceNotificationService.

davidfowl avatar Jun 04 '24 05:06 davidfowl