Skip to content

Commit

Permalink
Merge branch '53-aspire-dotnet' into endpoint_sahil
Browse files Browse the repository at this point in the history
  • Loading branch information
Diane-Choi committed Dec 5, 2024
2 parents 1888004 + 23dea90 commit 294eac6
Show file tree
Hide file tree
Showing 20 changed files with 301 additions and 18 deletions.
6 changes: 4 additions & 2 deletions src/AccountGoWeb/AccountGoWeb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
<ItemGroup>
<ProjectReference Include="../Dto/Dto.csproj" />
<ProjectReference Include="../Infrastructure/Infrastructure.csproj" />
<ProjectReference Include="../LibraryGDB/LibraryGDB.csproj" />
<ProjectReference Include="../src.ServiceDefaults/src.ServiceDefaults.csproj" />
<ProjectReference Include="..\LibraryGDB\LibraryGDB.csproj" />
</ItemGroup>

<ItemGroup>
Expand All @@ -32,7 +33,8 @@
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.QuickGrid" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.QuickGrid.EntityFrameworkAdapter" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />

<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.0" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions src/AccountGoWeb/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public IActionResult SignIn(string? returnUrl = null)
public async Task<IActionResult> SignIn(LoginViewModel model, string? returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;
//

if (ModelState.IsValid)
{
Expand Down
8 changes: 6 additions & 2 deletions src/AccountGoWeb/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
using AutoMapper;
using Microsoft.AspNetCore.Session;



var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();

// Add services to the container.

// Mapping
Expand All @@ -13,9 +17,9 @@
builder.Services.AddControllersWithViews();
builder.Services.AddHttpContextAccessor();

// string urlhost = System.Environment.GetEnvironmentVariable("APIHOST") ?? "localhost";
// string urlport = System.Environment.GetEnvironmentVariable("APIPORT") ?? "8001";

string apiurl = System.Environment.GetEnvironmentVariable("APIURL") ?? "http://localhost:8001/api/";

builder.Configuration["ApiUrl"] = apiurl;
System.Console.WriteLine($"[ASPNETCORE SERVER] API URL {builder.Configuration["ApiUrl"]}");

Expand Down
8 changes: 4 additions & 4 deletions src/AccountGoWeb/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:8000",
"applicationUrl": "http://localhost:8000/",
"sslPort": 0
}
},
Expand All @@ -18,10 +18,10 @@
"AccountGoWeb": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "http://localhost:8000/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:8000"
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/AccountGoWeb/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
}
},
"AllowedHosts": "*",
"ApiUrl": "http://{0}:{1}/api/"
"ApiUrl": "http://localhost:8001/api/"
}
2 changes: 1 addition & 1 deletion src/AccountGoWeb/appsettings.Production.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"ApiUrl": "http://{0}:{1}/api/"
"ApiUrl": "http://localhost:8001/api/"
}
11 changes: 9 additions & 2 deletions src/AccountGoWeb/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
"Microsoft.Hosting.Lifetime": "Information"
}
},
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:8000"
}
}
},
"AllowedHosts": "*",
"ApiUrl": "http://{0}:{1}/api/"
}
"ApiUrl": "http://localhost:8001/api/"
}
4 changes: 3 additions & 1 deletion src/Api/Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ProjectReference Include="../Core/Core.csproj" />
<ProjectReference Include="../Dto/Dto.csproj" />
<ProjectReference Include="../Services/Services.csproj" />
<ProjectReference Include="../src.ServiceDefaults/src.ServiceDefaults.csproj" />
</ItemGroup>

<ItemGroup>
Expand All @@ -24,7 +25,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />

<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.0" />
Expand Down
3 changes: 2 additions & 1 deletion src/Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.AddServiceDefaults();

// Validation
builder.Services.AddScoped<ValidationFilterAttribute>();
Expand Down
6 changes: 3 additions & 3 deletions src/Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
"Api": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "http://localhost:8001/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DBSERVER": "localhost,1444",
"DBUSERID": "sa",
"DBPASSWORD": "SqlPassword!"
},
"applicationUrl": "http://localhost:8001/"
}
}
}
}
}
7 changes: 7 additions & 0 deletions src/Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@
},
"SECRET": {
"key": "GoodDeedBooks1234GoodDeedBooks1234"
},
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:8001"
}
}
}
}
2 changes: 1 addition & 1 deletion src/GoodBooksReact/src/components/Shared/Config/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Config = {
API_URL: `http://localhost:8001/api/`,
API_URL: `http://localhost:1/api/`,
};

export default Config;
17 changes: 17 additions & 0 deletions src/src.AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Reflection;
using Google.Protobuf.WellKnownTypes;

var builder = DistributedApplication.CreateBuilder(args);



var api = builder.AddProject<Projects.Api>("api");



builder.AddProject<Projects.AccountGoWeb>("mvc")
.WithReference(api);


builder.Build().Run();

29 changes: 29 additions & 0 deletions src/src.AppHost/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17118;http://localhost:15251",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21083",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22106"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15251",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19070",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20256"
}
}
}
}
8 changes: 8 additions & 0 deletions src/src.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 src/src.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"
}
}
}
21 changes: 21 additions & 0 deletions src/src.AppHost/src.AppHost.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>13ebf7e1-4bc3-4178-925c-d2b16f2f0006</UserSecretsId>
</PropertyGroup>

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

<ItemGroup>
<ProjectReference Include="..\AccountGoWeb\AccountGoWeb.csproj" />
<ProjectReference Include="..\Api\Api.csproj" />
</ItemGroup>

</Project>
111 changes: 111 additions & 0 deletions src/src.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;
}
}
22 changes: 22 additions & 0 deletions src/src.ServiceDefaults/src.ServiceDefaults.csproj
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.10.0" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="8.2.2" />
<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>
Loading

0 comments on commit 294eac6

Please sign in to comment.