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

Aspire #30

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"skarnes20_Kjetil.Demo.Api" /o:"skarnes20" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:"sonar.verbose=true" /d:"sonar.dotnet.excludeTestProjects=true" /d:"sonar.cs.opencover.reportsPaths=**/coverage.opencover.xml" /d:sonar.host.url="https://sonarcloud.io"
dotnet restore Kjetil.Demo.Api.sln
dotnet build Kjetil.Demo.Api.sln --no-restore --configuration Release
dotnet test Kjetil.Demo.Api.sln --no-restore --configuration Release --collect:"XPlat Code Coverage;Format=opencover"
dotnet restore Code4Fun.Demo.Api.sln
dotnet build Code4Fun.Demo.Api.sln --no-restore --configuration Release
dotnet test Code4Fun.Demo.Api.sln --no-restore --configuration Release --collect:"XPlat Code Coverage;Format=opencover"
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
84 changes: 84 additions & 0 deletions Code4Fun.Demo.Api.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.13.35507.96
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{3C88B2B2-0CCE-47D6-B617-D774365F4224}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Code4Fun.Demo.Api", "src\Code4Fun.Demo.Api\Code4Fun.Demo.Api.csproj", "{041156F8-8CCD-2865-26DF-F42A0A1526DE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Code4Fun.Demo.DataAccess", "src\Code4Fun.Demo.DataAccess\Code4Fun.Demo.DataAccess.csproj", "{1DAB79F3-8EB4-34A2-C230-836C9F1C3369}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Code4Fun.Demo.Service", "src\Code4Fun.Demo.Service\Code4Fun.Demo.Service.csproj", "{91CDD5B5-ED2E-9B24-1017-06AF5B953050}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Code4Fun.Demo.Shared", "src\Code4Fun.Demo.Shared\Code4Fun.Demo.Shared.csproj", "{F1D0A550-0418-9155-77EB-5B567124AD20}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Code4Fun.Demo.Api.UnitTest", "tests\Code4Fun.Demo.Api.UnitTest\Code4Fun.Demo.Api.UnitTest.csproj", "{EBF2F6E5-D113-78C1-5348-86221B8A3B4C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Code4Fun.Demo.DataAccess.UnitTest", "tests\Code4Fun.Demo.DataAccess.UnitTest\Code4Fun.Demo.DataAccess.UnitTest.csproj", "{B22CA01C-C143-FCC7-3FF9-DD443B0B3DED}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Code4Fun.Demo.Service.UnitTest", "tests\Code4Fun.Demo.Service.UnitTest\Code4Fun.Demo.Service.UnitTest.csproj", "{D4CE3317-C858-52A6-CFE6-09899C4B0B4E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Code4Fun.Demo.Api.AppHost", "aspire\Code4Fun.Demo.Api.AppHost\Code4Fun.Demo.Api.AppHost.csproj", "{0DA7E264-56F3-47F6-88C6-B9B21E759F85}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Code4Fun.Demo.Api.ServiceDefaults", "aspire\Code4Fun.Demo.Api.ServiceDefaults\Code4Fun.Demo.Api.ServiceDefaults.csproj", "{928EBEB6-595C-48FF-969D-025E1B4B5AF4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "aspire", "aspire", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{041156F8-8CCD-2865-26DF-F42A0A1526DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{041156F8-8CCD-2865-26DF-F42A0A1526DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{041156F8-8CCD-2865-26DF-F42A0A1526DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{041156F8-8CCD-2865-26DF-F42A0A1526DE}.Release|Any CPU.Build.0 = Release|Any CPU
{1DAB79F3-8EB4-34A2-C230-836C9F1C3369}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1DAB79F3-8EB4-34A2-C230-836C9F1C3369}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1DAB79F3-8EB4-34A2-C230-836C9F1C3369}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1DAB79F3-8EB4-34A2-C230-836C9F1C3369}.Release|Any CPU.Build.0 = Release|Any CPU
{91CDD5B5-ED2E-9B24-1017-06AF5B953050}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{91CDD5B5-ED2E-9B24-1017-06AF5B953050}.Debug|Any CPU.Build.0 = Debug|Any CPU
{91CDD5B5-ED2E-9B24-1017-06AF5B953050}.Release|Any CPU.ActiveCfg = Release|Any CPU
{91CDD5B5-ED2E-9B24-1017-06AF5B953050}.Release|Any CPU.Build.0 = Release|Any CPU
{F1D0A550-0418-9155-77EB-5B567124AD20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F1D0A550-0418-9155-77EB-5B567124AD20}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F1D0A550-0418-9155-77EB-5B567124AD20}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F1D0A550-0418-9155-77EB-5B567124AD20}.Release|Any CPU.Build.0 = Release|Any CPU
{EBF2F6E5-D113-78C1-5348-86221B8A3B4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EBF2F6E5-D113-78C1-5348-86221B8A3B4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EBF2F6E5-D113-78C1-5348-86221B8A3B4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EBF2F6E5-D113-78C1-5348-86221B8A3B4C}.Release|Any CPU.Build.0 = Release|Any CPU
{B22CA01C-C143-FCC7-3FF9-DD443B0B3DED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B22CA01C-C143-FCC7-3FF9-DD443B0B3DED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B22CA01C-C143-FCC7-3FF9-DD443B0B3DED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B22CA01C-C143-FCC7-3FF9-DD443B0B3DED}.Release|Any CPU.Build.0 = Release|Any CPU
{D4CE3317-C858-52A6-CFE6-09899C4B0B4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4CE3317-C858-52A6-CFE6-09899C4B0B4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4CE3317-C858-52A6-CFE6-09899C4B0B4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4CE3317-C858-52A6-CFE6-09899C4B0B4E}.Release|Any CPU.Build.0 = Release|Any CPU
{0DA7E264-56F3-47F6-88C6-B9B21E759F85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0DA7E264-56F3-47F6-88C6-B9B21E759F85}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0DA7E264-56F3-47F6-88C6-B9B21E759F85}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0DA7E264-56F3-47F6-88C6-B9B21E759F85}.Release|Any CPU.Build.0 = Release|Any CPU
{928EBEB6-595C-48FF-969D-025E1B4B5AF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{928EBEB6-595C-48FF-969D-025E1B4B5AF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{928EBEB6-595C-48FF-969D-025E1B4B5AF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{928EBEB6-595C-48FF-969D-025E1B4B5AF4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{EBF2F6E5-D113-78C1-5348-86221B8A3B4C} = {3C88B2B2-0CCE-47D6-B617-D774365F4224}
{B22CA01C-C143-FCC7-3FF9-DD443B0B3DED} = {3C88B2B2-0CCE-47D6-B617-D774365F4224}
{D4CE3317-C858-52A6-CFE6-09899C4B0B4E} = {3C88B2B2-0CCE-47D6-B617-D774365F4224}
{0DA7E264-56F3-47F6-88C6-B9B21E759F85} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{928EBEB6-595C-48FF-969D-025E1B4B5AF4} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {833BEACA-3A59-4F8E-A5B0-C64CDF3C611F}
EndGlobalSection
EndGlobal
68 changes: 0 additions & 68 deletions Kjetil.Demo.Api.sln

This file was deleted.

22 changes: 22 additions & 0 deletions aspire/Code4Fun.Demo.Api.AppHost/Code4Fun.Demo.Api.AppHost.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0" />

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>5df1985e-419f-45ad-a8f6-d60e5ff29f6f</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Code4Fun.Demo.Api\Code4Fun.Demo.Api.csproj" />
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions aspire/Code4Fun.Demo.Api.AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var builder = DistributedApplication.CreateBuilder(args);

builder.AddProject<Projects.Code4Fun_Demo_Api>("demo-api");

await builder.Build().RunAsync();
17 changes: 17 additions & 0 deletions aspire/Code4Fun.Demo.Api.AppHost/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17130;http://localhost:15214",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21221",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22245"
}
}
}
}
8 changes: 8 additions & 0 deletions aspire/Code4Fun.Demo.Api.AppHost/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions aspire/Code4Fun.Demo.Api.AppHost/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireSharedProject>true</IsAspireSharedProject>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />

<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="9.0.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0" />
</ItemGroup>

</Project>
95 changes: 95 additions & 0 deletions aspire/Code4Fun.Demo.Api.ServiceDefaults/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Logging;
using OpenTelemetry;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;

namespace Microsoft.Extensions.Hosting;

// Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry.
// This project should be referenced by each service project in your solution.
// To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults
public static class Extensions
{
public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
builder.ConfigureOpenTelemetry();

builder.AddDefaultHealthChecks();

builder.Services.AddServiceDiscovery();

builder.Services.ConfigureHttpClientDefaults(http =>
{
http.AddStandardResilienceHandler();
http.AddServiceDiscovery();
});

return builder;
}

public static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
builder.Logging.AddOpenTelemetry(logging =>
{
logging.IncludeFormattedMessage = true;
logging.IncludeScopes = true;
});

builder.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation();
})
.WithTracing(tracing =>
{
tracing.AddSource(builder.Environment.ApplicationName)
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation();
});

builder.AddOpenTelemetryExporters();

return builder;
}

private static TBuilder AddOpenTelemetryExporters<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);

if (useOtlpExporter)
{
builder.Services.AddOpenTelemetry().UseOtlpExporter();
}

return builder;
}

public static TBuilder AddDefaultHealthChecks<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
builder.Services.AddHealthChecks()
.AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]);

return builder;
}

public static WebApplication MapDefaultEndpoints(this WebApplication app)
{
if (app.Environment.IsDevelopment())
{
app.MapHealthChecks("/health");

app.MapHealthChecks("/alive", new HealthCheckOptions
{
Predicate = r => r.Tags.Contains("live")
});
}

return app;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Kjetil.Demo.Service\Kjetil.Demo.Service.csproj" />
<ProjectReference Include="..\..\aspire\Code4Fun.Demo.Api.ServiceDefaults\Code4Fun.Demo.Api.ServiceDefaults.csproj" />
<ProjectReference Include="..\Code4Fun.Demo.Service\Code4Fun.Demo.Service.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
namespace Kjetil.Demo.Api.Controllers;
namespace Code4Fun.Demo.Api.Controllers;

/// <summary>
/// Defines the weather forecast controller
/// </summary>
/// <param name="service">Weather Service</param>
[ApiController]
[Route("api/forecast")]
public class WeatherForecastController(IWeatherService service) : ControllerBase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
global using Kjetil.Demo.Api.Infrastructure;
global using Kjetil.Demo.Service;
global using Kjetil.Demo.Service.Infrastructure;
global using Kjetil.Demo.Shared.ViewModels;
global using Code4Fun.Demo.Api.Infrastructure;
global using Code4Fun.Demo.Service;
global using Code4Fun.Demo.Service.Infrastructure;
global using Code4Fun.Demo.Shared.ViewModels;
global using Microsoft.AspNetCore.Builder;
global using Microsoft.AspNetCore.Hosting;
global using Microsoft.AspNetCore.Mvc;
Expand Down
Loading