Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/rstropek/Samples
Browse files Browse the repository at this point in the history
  • Loading branch information
rstropek committed Jul 11, 2024
2 parents eab3c5b + bfd5aab commit 58c59a9
Show file tree
Hide file tree
Showing 53 changed files with 14,100 additions and 4 deletions.
24 changes: 24 additions & 0 deletions Aspire/AspireDemo/AspireDemo.AppHost/AspireDemo.AppHost.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>6aace7c8-3418-41a2-870a-b2ee07b1cb02</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="8.0.1" />
<PackageReference Include="Aspire.Hosting.Azure.Sql" Version="8.0.1" />
<PackageReference Include="Aspire.Hosting.NodeJs" Version="8.0.1" />
<PackageReference Include="Aspire.Hosting.SqlServer" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MultiplierApi\MultiplierApi.csproj" />
<ProjectReference Include="..\WebApi\WebApi.csproj" />
</ItemGroup>

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

var sql = builder.AddSqlServer("sql")
.PublishAsAzureSqlDatabase();
var sqldb = sql.AddDatabase("sqldb");

var multiplier = builder.AddProject<Projects.MultiplierApi>("multiplierapi")
.WithReplicas(2);

var webapi = builder.AddProject<Projects.WebApi>("webapi")
.WithReference(sqldb)
.WithReference(multiplier);

builder.AddNpmApp("angular", "../Frontend")
.WithReference(webapi)
.WithHttpEndpoint(env: "PORT")
.WithExternalHttpEndpoints()
.PublishAsDockerFile();

builder.Build().Run();
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/AspireDemo/AspireDemo.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>net8.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="8.5.0" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="8.0.1" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.8.1" />
</ItemGroup>

</Project>
111 changes: 111 additions & 0 deletions Aspire/AspireDemo/AspireDemo.ServiceDefaults/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
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 IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBuilder builder)
{
builder.ConfigureOpenTelemetry();

builder.AddDefaultHealthChecks();

builder.Services.AddServiceDiscovery();

builder.Services.ConfigureHttpClientDefaults(http =>
{
// Turn on resilience by default
http.AddStandardResilienceHandler();

// Turn on service discovery by default
http.AddServiceDiscovery();
});

return builder;
}

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

builder.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation();
})
.WithTracing(tracing =>
{
tracing.AddAspNetCoreInstrumentation()
// Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
//.AddGrpcClientInstrumentation()
.AddHttpClientInstrumentation();
});

builder.AddOpenTelemetryExporters();

return builder;
}

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

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

// Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package)
//if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]))
//{
// builder.Services.AddOpenTelemetry()
// .UseAzureMonitor();
//}

return builder;
}

public static IHostApplicationBuilder AddDefaultHealthChecks(this IHostApplicationBuilder builder)
{
builder.Services.AddHealthChecks()
// Add a default liveness check to ensure app is responsive
.AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]);

return builder;
}

public static WebApplication MapDefaultEndpoints(this WebApplication app)
{
// Adding health checks endpoints to applications in non-development environments has security implications.
// See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments.
if (app.Environment.IsDevelopment())
{
// All health checks must pass for app to be considered ready to accept traffic after starting
app.MapHealthChecks("/health");

// Only health checks tagged with the "live" tag must pass for app to be considered alive
app.MapHealthChecks("/alive", new HealthCheckOptions
{
Predicate = r => r.Tags.Contains("live")
});
}

return app;
}
}
42 changes: 42 additions & 0 deletions Aspire/AspireDemo/AspireDemo.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.34928.147
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspireDemo.AppHost", "AspireDemo.AppHost\AspireDemo.AppHost.csproj", "{D8140686-2E34-4CFE-9B78-21EC53258FA3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspireDemo.ServiceDefaults", "AspireDemo.ServiceDefaults\AspireDemo.ServiceDefaults.csproj", "{530481E1-CD02-4300-9B1A-B1A01D62470B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApi", "WebApi\WebApi.csproj", "{BA99069E-2586-46E3-AE3E-ABF69DCB90E2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MultiplierApi", "MultiplierApi\MultiplierApi.csproj", "{311F8FFE-E5DC-43A3-8182-3C94F309419B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D8140686-2E34-4CFE-9B78-21EC53258FA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D8140686-2E34-4CFE-9B78-21EC53258FA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8140686-2E34-4CFE-9B78-21EC53258FA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8140686-2E34-4CFE-9B78-21EC53258FA3}.Release|Any CPU.Build.0 = Release|Any CPU
{530481E1-CD02-4300-9B1A-B1A01D62470B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{530481E1-CD02-4300-9B1A-B1A01D62470B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{530481E1-CD02-4300-9B1A-B1A01D62470B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{530481E1-CD02-4300-9B1A-B1A01D62470B}.Release|Any CPU.Build.0 = Release|Any CPU
{BA99069E-2586-46E3-AE3E-ABF69DCB90E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA99069E-2586-46E3-AE3E-ABF69DCB90E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA99069E-2586-46E3-AE3E-ABF69DCB90E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA99069E-2586-46E3-AE3E-ABF69DCB90E2}.Release|Any CPU.Build.0 = Release|Any CPU
{311F8FFE-E5DC-43A3-8182-3C94F309419B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{311F8FFE-E5DC-43A3-8182-3C94F309419B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{311F8FFE-E5DC-43A3-8182-3C94F309419B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{311F8FFE-E5DC-43A3-8182-3C94F309419B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {25B518D4-2305-4F11-BB87-4B3A1C25691C}
EndGlobalSection
EndGlobal
42 changes: 42 additions & 0 deletions Aspire/AspireDemo/Frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# See https://docs.github.com/get-started/getting-started-with-git/ignoring-files for more about ignoring files.

# Compiled output
/dist
/tmp
/out-tsc
/bazel-out

# Node
/node_modules
npm-debug.log
yarn-error.log

# IDEs and editors
.idea/
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# Visual Studio Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*

# Miscellaneous
/.angular/cache
.sass-cache/
/connect.lock
/coverage
/libpeerconnection.log
testem.log
/typings

# System files
.DS_Store
Thumbs.db
106 changes: 106 additions & 0 deletions Aspire/AspireDemo/Frontend/angular.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"Frontend": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"inlineTemplate": true,
"inlineStyle": true,
"skipTests": true
},
"@schematics/angular:class": {
"skipTests": true
},
"@schematics/angular:directive": {
"skipTests": true
},
"@schematics/angular:guard": {
"skipTests": true
},
"@schematics/angular:interceptor": {
"skipTests": true
},
"@schematics/angular:pipe": {
"skipTests": true
},
"@schematics/angular:resolver": {
"skipTests": true
},
"@schematics/angular:service": {
"skipTests": true
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:application",
"options": {
"outputPath": "dist/frontend",
"index": "src/index.html",
"browser": "src/main.ts",
"polyfills": [
"zone.js"
],
"tsConfig": "tsconfig.app.json",
"assets": [
{
"glob": "**/*",
"input": "public"
}
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kB",
"maximumError": "1MB"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kB",
"maximumError": "4kB"
}
],
"outputHashing": "all"
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"buildTarget": "Frontend:build:production"
},
"development": {
"buildTarget": "Frontend:build:development"
}
},
"defaultConfiguration": "development",
"options": {
"proxyConfig": "proxy.conf.js"
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n"
}
}
}
}
}
Loading

0 comments on commit 58c59a9

Please sign in to comment.