-
Notifications
You must be signed in to change notification settings - Fork 182
/
Program.cs
41 lines (29 loc) · 1.2 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//var builder = DistributedApplication.CreateBuilder(new DistributedApplicationOptions { Args = args, AssemblyName = typeof(Program).Assembly.GetName().Name });
var builder = DistributedApplication.CreateBuilder(args);
var cache = builder.AddRedis("cache");
builder.AddProject<Projects.AspireIntegrationTesting_ApiService>("apiservice")
.WithReference(cache);
builder.ApplyResourceFilter();
builder.Build().Run();
public static class Extensions
{
private static readonly char[] FilterSeparator = [';'];
public static IDistributedApplicationBuilder ApplyResourceFilter(this IDistributedApplicationBuilder builder, string? filter = null)
{
filter ??= builder.Configuration["ResourceFilter"];
if (filter is null)
{
return builder;
}
var candidates = filter.Split(FilterSeparator, StringSplitOptions.RemoveEmptyEntries);
for (int i = builder.Resources.Count - 1; i >= 0; i--)
{
var resource = builder.Resources[i];
if (!candidates.Contains(resource.Name, StringComparer.OrdinalIgnoreCase))
{
builder.Resources.Remove(resource);
}
}
return builder;
}
}