Skip to content

Commit

Permalink
Update to aspire preview3 (#166)
Browse files Browse the repository at this point in the history
* Update to aspire preview3

* Make preview3 work

* Remove container image base

* Name fixes

* Fix connections

* Remove placeholder uri logic

* Work around SDK bug

* Fix images

* Use ContainerRepository

* Fixed registry

* Fixed jwt keys

* Disable key rotation for now

* Made it work
- Added forwarded headers setting

* Remove warning suppression from Aspire components.

dotnet/runtime#94117 has been fixed and flown to the Aspire components. They no longer produce AOT warnings.

* - Remove temporary nuget.config
- Update to official Aspire preview3
    - Fix up some Extensions code to conform to latest template

* Remove unnecessary .sln file

* Remove ContainerBaseImage change.

---------

Co-authored-by: David Fowler <davidfowl@gmail.com>
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
Co-authored-by: Aditya Mandaleeka <adityam@microsoft.com>
  • Loading branch information
4 people authored Feb 15, 2024
1 parent bf72068 commit 228aaf0
Show file tree
Hide file tree
Showing 20 changed files with 104 additions and 69 deletions.
4 changes: 0 additions & 4 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
<ItemGroup>
<!-- https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/1410 is tracking fixing the one EventSource warning in RabbitMQ. -->
<IlcArg Include="--singlewarnassembly:RabbitMQ.Client" />

<!-- https://github.com/dotnet/runtime/issues/94117 will fix the warnings coming from the ConfigBinder source generator in these assemblies. -->
<IlcArg Include="--singlewarnassembly:Aspire.RabbitMQ.Client" />
<IlcArg Include="--singlewarnassembly:Aspire.StackExchange.Redis" />
</ItemGroup>
</Target>

Expand Down
14 changes: 6 additions & 8 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
<AspnetVersion>8.0.0</AspnetVersion>
<MicrosoftExtensionsVersion>8.0.0</MicrosoftExtensionsVersion>
<AspnetVersion>8.0.1</AspnetVersion>
<MicrosoftExtensionsVersion>8.1.0</MicrosoftExtensionsVersion>
<EfVersion>8.0.0</EfVersion>
<RuntimeVersion>8.0.0</RuntimeVersion>
<AspireVersion>8.0.0-preview.2.23619.3</AspireVersion>
<AspireVersion>8.0.0-preview.3.24105.21</AspireVersion>
<GrpcVersion>2.59.0</GrpcVersion>
</PropertyGroup>
<ItemGroup>
Expand Down Expand Up @@ -38,9 +37,9 @@
<PackageVersion Include="Pgvector" Version="0.2.0" />
<PackageVersion Include="Pgvector.EntityFrameworkCore" Version="0.2.0" />
<!-- Version together with runtime -->
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="$(RuntimeVersion)" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="$(RuntimeVersion)" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(RuntimeVersion)" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<!-- Xabaril packages -->
<PackageVersion Include="AspNetCore.HealthChecks.Uris" Version="7.0.0" />
<!-- AI -->
Expand All @@ -50,7 +49,6 @@
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.7.0-alpha.1" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.7.0-alpha.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.6.0-beta.2" />
<PackageVersion Include="OpenTelemetry.Instrumentation.EventCounters" Version="1.5.1-alpha.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.GrpcNetClient" Version="1.6.0-beta.2" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.6.0-beta.2" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.5.1" />
Expand Down
2 changes: 1 addition & 1 deletion src/Basket.API/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void AddApplicationServices(this IHostApplicationBuilder builder)

builder.Services.AddSingleton<IBasketRepository, RedisBasketRepository>();

builder.AddRabbitMqEventBus("EventBus")
builder.AddRabbitMqEventBus("eventbus")
.AddSubscription<OrderStartedIntegrationEvent, OrderStartedIntegrationEventHandler>()
.ConfigureJsonOptions(options => options.TypeInfoResolverChain.Add(IntegrationEventContext.Default));
}
Expand Down
20 changes: 0 additions & 20 deletions src/Catalog.API/Apis/CatalogApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public static async Task<Results<Ok<PaginatedItems<CatalogItem>>, BadRequest<str
.Take(pageSize)
.ToListAsync();

itemsOnPage = ChangeUriPlaceholder(services.Options.Value, itemsOnPage);

return TypedResults.Ok(new PaginatedItems<CatalogItem>(pageIndex, pageSize, totalItems, itemsOnPage));
}

Expand All @@ -57,7 +55,6 @@ public static async Task<Ok<List<CatalogItem>>> GetItemsByIds(
int[] ids)
{
var items = await services.Context.CatalogItems.Where(item => ids.Contains(item.Id)).ToListAsync();
items = ChangeUriPlaceholder(services.Options.Value, items);
return TypedResults.Ok(items);
}

Expand All @@ -77,7 +74,6 @@ public static async Task<Results<Ok<CatalogItem>, NotFound, BadRequest<string>>>
return TypedResults.NotFound();
}

item.PictureUri = services.Options.Value.PicBaseUrl.Replace("[0]", item.Id.ToString());
return TypedResults.Ok(item);
}

Expand All @@ -99,8 +95,6 @@ public static async Task<Ok<PaginatedItems<CatalogItem>>> GetItemsByName(
.Take(pageSize)
.ToListAsync();

itemsOnPage = ChangeUriPlaceholder(services.Options.Value, itemsOnPage);

return TypedResults.Ok(new PaginatedItems<CatalogItem>(pageIndex, pageSize, totalItems, itemsOnPage));
}

Expand Down Expand Up @@ -166,8 +160,6 @@ public static async Task<Results<BadRequest<string>, RedirectToRouteHttpResult,
.ToListAsync();
}

itemsOnPage = ChangeUriPlaceholder(services.Options.Value, itemsOnPage);

return TypedResults.Ok(new PaginatedItems<CatalogItem>(pageIndex, pageSize, totalItems, itemsOnPage));
}

Expand Down Expand Up @@ -195,7 +187,6 @@ public static async Task<Ok<PaginatedItems<CatalogItem>>> GetItemsByBrandAndType
.Take(pageSize)
.ToListAsync();

itemsOnPage = ChangeUriPlaceholder(services.Options.Value, itemsOnPage);
return TypedResults.Ok(new PaginatedItems<CatalogItem>(pageIndex, pageSize, totalItems, itemsOnPage));
}

Expand All @@ -222,7 +213,6 @@ public static async Task<Ok<PaginatedItems<CatalogItem>>> GetItemsByBrandId(
.Take(pageSize)
.ToListAsync();

itemsOnPage = ChangeUriPlaceholder(services.Options.Value, itemsOnPage);
return TypedResults.Ok(new PaginatedItems<CatalogItem>(pageIndex, pageSize, totalItems, itemsOnPage));
}

Expand Down Expand Up @@ -305,16 +295,6 @@ public static async Task<Results<NoContent, NotFound>> DeleteItemById(
return TypedResults.NoContent();
}

private static List<CatalogItem> ChangeUriPlaceholder(CatalogOptions options, List<CatalogItem> items)
{
foreach (var item in items)
{
item.PictureUri = options.PicBaseUrl.Replace("[0]", item.Id.ToString());
}

return items;
}

private static string GetImageMimeTypeFromImageFileExtension(string extension) => extension switch
{
".png" => "image/png",
Expand Down
3 changes: 3 additions & 0 deletions src/Catalog.API/Catalog.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
<ProjectReference Include="..\eShop.ServiceDefaults\eShop.ServiceDefaults.csproj" />
</ItemGroup>

<ItemGroup>
<Content Include="Pics\*.webp" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Catalog.FunctionalTests" />
Expand Down
4 changes: 2 additions & 2 deletions src/Catalog.API/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static class Extensions
{
public static void AddApplicationServices(this IHostApplicationBuilder builder)
{
builder.AddNpgsqlDbContext<CatalogContext>("CatalogDB", configureDbContextOptions: dbContextOptionsBuilder =>
builder.AddNpgsqlDbContext<CatalogContext>("catalogdb", configureDbContextOptions: dbContextOptionsBuilder =>
{
dbContextOptionsBuilder.UseNpgsql(builder =>
{
Expand All @@ -20,7 +20,7 @@ public static void AddApplicationServices(this IHostApplicationBuilder builder)

builder.Services.AddTransient<ICatalogIntegrationEventService, CatalogIntegrationEventService>();

builder.AddRabbitMqEventBus("EventBus")
builder.AddRabbitMqEventBus("eventbus")
.AddSubscription<OrderStatusChangedToAwaitingValidationIntegrationEvent, OrderStatusChangedToAwaitingValidationIntegrationEventHandler>()
.AddSubscription<OrderStatusChangedToPaidIntegrationEvent, OrderStatusChangedToPaidIntegrationEventHandler>();

Expand Down
3 changes: 0 additions & 3 deletions src/Catalog.API/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"ConnectionStrings": {
"CatalogDB": "Host=localhost;Database=CatalogDB;Username=postgres;Password=yourWeak(!)Password"
},
"CatalogOptions": {
"PicBaseUrl": "http://localhost:5222/api/v1/catalog/items/[0]/pic/"
}
}
5 changes: 5 additions & 0 deletions src/Identity.API/Identity.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
<ItemGroup>
<ProjectReference Include="..\eShop.ServiceDefaults\eShop.ServiceDefaults.csproj" />
</ItemGroup>

<ItemGroup>
<!-- Don't use this in production -->
<Content Include="tempkey.jwk" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\Shared\MigrateDbContextExtensions.cs" Link="Extensions\MigrateDbContextExtensions.cs" />
Expand Down
8 changes: 6 additions & 2 deletions src/Identity.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

builder.Services.AddControllersWithViews();

builder.AddNpgsqlDbContext<ApplicationDbContext>("IdentityDB");
builder.AddNpgsqlDbContext<ApplicationDbContext>("identitydb");

// Apply database migration automatically. Note that this approach is not
// recommended for production scenarios. Consider generating SQL scripts from
Expand All @@ -24,13 +24,17 @@
options.Events.RaiseInformationEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseSuccessEvents = true;
// TODO: Remove this line in production.
options.KeyManagement.Enabled = false;
})
.AddInMemoryIdentityResources(Config.GetResources())
.AddInMemoryApiScopes(Config.GetApiScopes())
.AddInMemoryApiResources(Config.GetApis())
.AddInMemoryClients(Config.GetClients(builder.Configuration))
.AddAspNetIdentity<ApplicationUser>()
.AddDeveloperSigningCredential(); // Not recommended for production - you need to store your key material somewhere secure
// TODO: Not recommended for production - you need to store your key material somewhere secure
.AddDeveloperSigningCredential();

builder.Services.AddTransient<IProfileService, ProfileService>();
builder.Services.AddTransient<ILoginService<ApplicationUser>, EFLoginService>();
Expand Down
8 changes: 8 additions & 0 deletions src/Identity.API/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5243;http://localhost:5223",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
1 change: 0 additions & 1 deletion src/Mobile.Bff.Shopping/Mobile.Bff.Shopping.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ContainerBaseImage>mobileshoppingagg</ContainerBaseImage>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Mobile.Bff.Shopping/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"http": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "http://localhost:61632/",
"applicationUrl": "http://localhost:11632/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
4 changes: 2 additions & 2 deletions src/OrderProcessor/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ public static class Extensions
{
public static void AddApplicationServices(this IHostApplicationBuilder builder)
{
builder.AddRabbitMqEventBus("EventBus")
builder.AddRabbitMqEventBus("eventbus")
.ConfigureJsonOptions(options => options.TypeInfoResolverChain.Add(IntegrationEventContext.Default));

builder.AddNpgsqlDataSource("OrderingDB");
builder.AddNpgsqlDataSource("orderingdb");

builder.Services.AddOptions<BackgroundTaskOptions>()
.BindConfiguration(nameof(BackgroundTaskOptions));
Expand Down
4 changes: 2 additions & 2 deletions src/Ordering.API/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static void AddApplicationServices(this IHostApplicationBuilder builder)
// Pooling is disabled because of the following error:
// Unhandled exception. System.InvalidOperationException:
// The DbContext of type 'OrderingContext' cannot be pooled because it does not have a public constructor accepting a single parameter of type DbContextOptions or has more than one constructor.
builder.AddNpgsqlDbContext<OrderingContext>("OrderingDB", settings => settings.DbContextPooling = false);
builder.AddNpgsqlDbContext<OrderingContext>("orderingdb", settings => settings.DbContextPooling = false);

services.AddMigration<OrderingContext, OrderingContextSeed>();

Expand All @@ -19,7 +19,7 @@ public static void AddApplicationServices(this IHostApplicationBuilder builder)

services.AddTransient<IOrderingIntegrationEventService, OrderingIntegrationEventService>();

builder.AddRabbitMqEventBus("EventBus")
builder.AddRabbitMqEventBus("eventbus")
.AddEventBusSubscriptions();

services.AddHttpContextAccessor();
Expand Down
4 changes: 2 additions & 2 deletions src/Webhooks.API/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ public static void AddApplicationServices(this IHostApplicationBuilder builder)
{
builder.AddDefaultAuthentication();

builder.AddRabbitMqEventBus("EventBus")
builder.AddRabbitMqEventBus("eventbus")
.AddEventBusSubscriptions();

builder.AddNpgsqlDbContext<WebhooksContext>("WebHooksDB");
builder.AddNpgsqlDbContext<WebhooksContext>("webhooksdb");

builder.Services.AddMigration<WebhooksContext>();

Expand Down
36 changes: 36 additions & 0 deletions src/eShop.AppHost/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aspire.Hosting.Lifecycle;

namespace eShop.AppHost;

internal static class Extensions
{
/// <summary>
/// Adds a hook to set the ASPNETCORE_FORWARDEDHEADERS_ENABLED environment variable to true for all projects in the application.
/// </summary>
public static IDistributedApplicationBuilder AddForwardedHeaders(this IDistributedApplicationBuilder builder)
{
builder.Services.TryAddLifecycleHook<AddForwardHeadersHook>();
return builder;
}

private class AddForwardHeadersHook : IDistributedApplicationLifecycleHook
{
public Task BeforeStartAsync(DistributedApplicationModel appModel, CancellationToken cancellationToken = default)
{
foreach (var p in appModel.GetProjectResources())
{
p.Annotations.Add(new EnvironmentCallbackAnnotation(context =>
{
context.EnvironmentVariables["ASPNETCORE_FORWARDEDHEADERS_ENABLED"] = "true";
}));
}

return Task.CompletedTask;
}
}
}
Loading

0 comments on commit 228aaf0

Please sign in to comment.