Flagsmith / Flagsmith/flagsmith-dotnet-client

Add Aspire component

Open
#125 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
20
Forks
15
PR merge metrics
No merged PRs in 30d

Description

It would be amazing, if we can have Flagsmith [Aspire](https://learn.microsoft.com/en-us/dotnet/aspire/get-started/aspire-overview) component.
I can provide some help in development of this aspire component.

**Why?**
- There are such requests from the community dotnet/aspire#1570
- It's the easiest way to start using Flagsmith with .NET
- Improves Flagsmith adoption across community
- Adds support for automatic DI registration

**How it should look like**

```csharp
// AppHost.Program.cs

var builder = DistributedApplication.CreateBuilder(args);

var flagsmith = builder.AddFlagsmith();

var apiService = builder.AddProject("apiservice")
.WithEnvironment(flagsmith); // Pupulates URL and EnvironmentKey
```

```csharp
// ServiceDefaults.Extensions.cs

public static TBuilder AddServiceDefaults(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
builder.AddFlagsmithClient(); // Registers FlagsmithClient into DI with URL and EnvironmentKey
}
```

**Example of configuration with database**
```csharp
// AppHost.Program.cs

var builder = DistributedApplication.CreateBuilder(args);

var postgresServer = builder.AddPostgres("postgresserver")
// Mount the SQL scripts directory into the container.
// Init script would create a flagsmith database, becuase Aspire doesn't create DB by default yet.
.WithContainerName("postgresserver")
.WithBindMount("../Postgres", "/docker-entrypoint-initdb.d");

var flagsmithDatabase = postgresServer.AddDatabase("flagsmithDatabase", databaseName: "flagsmithdb");

var flagsmith = builder.AddFlagsmith()
.WithReference(flagsmithDatabase) // Populates DATABASE_URL
.WaitFor(flagsmithDatabase)

var apiService = builder.AddProject("apiservice")
.WithEnvironment(flagsmith);
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.