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

Add interfaces to PostgreSQL, Redis, and SqlServer Hosting Resources #6055

Open
eerhardt opened this issue Oct 1, 2024 · 2 comments
Open
Labels
area-integrations Issues pertaining to Aspire Integrations packages postgres Issues related to Postgres integrations redis Issues related to redis integrations
Milestone

Comments

@eerhardt
Copy link
Member

eerhardt commented Oct 1, 2024

Background and Motivation

See #5930 (comment) for some of the context.

With

We re-designed how resources that can be hosted in either a container or a managed Azure resource (ex. PostgreSQL, Redis, SqlServer) are added to the model.

Before

var redis = builder.AddRedis("redis")
                   .PublishAsAzureRedis();

After

var redis = builder.AddAzureRedis("redis")
                   .RunAsContainer();

The downside of this approach is composability of resources. Let's say I wanted to have a resource that depended on a Postgres database instance. With this change the implementor of that would need to have extensions for each cloud provider (unless they just allow any IResourceWithConnectionString).

Proposed API

namespace Aspire.Hosting.Redis;

public interface IRedisResource : IResourceWithConnectionString
{
}

namespace Aspire.Hosting.ApplicationModel;
public class RedisResource : IRedisResource {...} 

namespace Aspire.Hosting.Azure;
public class AzureRedisCacheResource : IRedisResource {...} 

namespace Aspire.Hosting.Postgres;

public interface IPostgresServerResource : IResourceWithConnectionString
{
}

namespace Aspire.Hosting.ApplicationModel;
public class PostgresServerResource : IPostgresServerResource {...}

namespace Aspire.Hosting.Azure;
public class AzurePostgresFlexibleServerResource : IPostgresServerResource {...}

namespace Aspire.Hosting.SqlServer;

public interface ISqlServerServerResource : IResourceWithConnectionString
{
}

namespace Aspire.Hosting.ApplicationModel;
public class SqlServerServerResource : ISqlServerServerResource  {...}

namespace Aspire.Hosting.Azure;
public class AzureSqlServerServerResource : ISqlServerServerResource  {...}

Usage Examples

var redis1 = builder.AddRedis("cache1");
UseRedis(redis1);

var redis2 = builder.AddAzureRedis("cache2");
UseRedis(redis2);

static void UseRedis(IResourceBuilder<IRedisResource> redis)
{
   ... get the connection string, or use the resource some other way
}

Alternative Designs

Risks

cc @davidfowl @mitchdenny

@davidfowl davidfowl added area-integrations Issues pertaining to Aspire Integrations packages enhancement postgres Issues related to Postgres integrations redis Issues related to redis integrations labels Oct 2, 2024
@mitchdenny
Copy link
Member

Yep - I think we need to do this otherwise we'll stifle reuse of some of these fundamental application building blocks. You'll end up with packages on NuGet that look like this:

MyAspireStuff.Postgres.Azure
MyAspireStuff.Postgres.AWS

... only because there isn't a shared type for the Redis resources.

@mitchdenny
Copy link
Member

I'm adding it to the backlog for now. I don't think we block 9.0 for it but I think it would be nice to see in 9.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-integrations Issues pertaining to Aspire Integrations packages postgres Issues related to Postgres integrations redis Issues related to redis integrations
Projects
None yet
Development

No branches or pull requests

3 participants