Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
fa78a55
создан
Matosik Feb 17, 2026
1ae7749
генерация данных через Bogus
Matosik Mar 11, 2026
6fb6c55
Создан нормальный генератор моделей, который относит модели к их прои…
Matosik Mar 11, 2026
1b19de4
веб сервер
Matosik Mar 12, 2026
f182de1
изменен README под 1 ЛР
Matosik Mar 13, 2026
e82dee3
Вроде всё готово
Matosik Mar 15, 2026
f96b71b
Нормальные логи
Matosik Mar 15, 2026
7af635e
sfdlhkj
Matosik Mar 16, 2026
4de7479
Написаны Unit тесты
Matosik Mar 16, 2026
839686a
Удалены ненужные дерективы using
Matosik Mar 16, 2026
13d2baa
Добавлены описания
Matosik Mar 16, 2026
5170a8d
значение ttl вынесено в appsetting.json
Matosik Mar 17, 2026
0197853
удален ненужный файл
Matosik Mar 17, 2026
990c578
delete string.Empty и добавлены описание описания(даже описания исклю…
Matosik Mar 18, 2026
08d75a0
Удален не используемый класс остался только Dto. Надеюсь это никого н…
Matosik Mar 18, 2026
ab5a2c8
написан primary constructor
Matosik Mar 18, 2026
9a94c4f
Seed => Id
Matosik Mar 18, 2026
975f080
Удалены ненужные закомиченые исключения и один файл = один класс
Matosik Mar 18, 2026
688ed74
лучший способ получать файл с производителями и моделями
Matosik Mar 18, 2026
34c5ec2
Меньше пустых строк
Matosik Mar 18, 2026
b0651bb
VehicleModelGenerator теперь не генератор а просто закрузчик данных д…
Matosik Mar 18, 2026
47f9b8f
JsonSerializerOptions вынесен в статическое поле
Matosik Mar 18, 2026
47fb48c
теперь data не может быть null так как выбросится исключение
Matosik Mar 18, 2026
1c1e4d2
Убрал лишнюю проверку
Matosik Mar 18, 2026
f49ba5e
primary конструктор
Matosik Mar 18, 2026
f1a7125
Удалено то чего быть не должно
Matosik Mar 18, 2026
50be3f3
порт вынесен в appsetting.json
Matosik Mar 18, 2026
d5767dd
primary constructor
Matosik Mar 18, 2026
c6b4c9b
страшная табуляция превратилась в шедевр искусства
Matosik Mar 18, 2026
3fc2ba7
Понижена гарантия валидации данных
Matosik Mar 18, 2026
7ddadc5
вынес адрес клиента в appsetting.json
Matosik Mar 18, 2026
0a0badb
ждем
Matosik Mar 18, 2026
46b43a6
Удален ненужный проект
Matosik Mar 19, 2026
f00be80
Asp => Server
Matosik Mar 19, 2026
850282c
Aspire.StackExchange.Redis.DistributedCaching
Matosik Mar 19, 2026
c1ddc10
cleanup code
Matosik Mar 19, 2026
ccfb2bb
fix
Matosik Mar 19, 2026
2230a46
update readme.md
Matosik Apr 9, 2026
f16e060
ApiGateway with Ocelot
Matosik Apr 9, 2026
af13308
Ready
Matosik Apr 9, 2026
cf104f5
Booger AIDS
Matosik Apr 9, 2026
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
17 changes: 17 additions & 0 deletions ApiGateway/ApiGateway.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Ocelot" Version="23.3.6" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Aspire.ServiceDefaults\Aspire.ServiceDefaults.csproj" />
</ItemGroup>

</Project>
41 changes: 41 additions & 0 deletions ApiGateway/Balancer/QueryBasedLoadBalancer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Ocelot.LoadBalancer.LoadBalancers;
using Ocelot.Responses;
using Ocelot.ServiceDiscovery.Providers;
using Ocelot.Values;

namespace ApiGateway.Balancer;

public sealed class QueryBasedLoadBalancer(
IServiceDiscoveryProvider serviceDiscovery) : ILoadBalancer
{
public string Type => nameof(QueryBasedLoadBalancer);

public async Task<Response<ServiceHostAndPort>> LeaseAsync(HttpContext httpContext)
{
var services = await serviceDiscovery.GetAsync();

if (services is null)
return new ErrorResponse<ServiceHostAndPort>(
new ServicesAreNullError("Service discovery returned null"));

if (services.Count == 0)
return new ErrorResponse<ServiceHostAndPort>(
new ServicesAreNullError("No downstream services are available"));

var service = SelectByQuery(httpContext, services);
return new OkResponse<ServiceHostAndPort>(service.HostAndPort);
}

private static Service SelectByQuery(HttpContext httpContext, List<Service> services)
{
var idRaw = httpContext.Request.Query["id"].FirstOrDefault();

if (!int.TryParse(idRaw, out var id))
return services[0];

var index = Math.Abs(id % services.Count);
return services[index];
}

public void Release(ServiceHostAndPort hostAndPort) { }
}
46 changes: 46 additions & 0 deletions ApiGateway/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using ApiGateway.Balancer;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;

var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();

builder.Configuration.AddJsonFile("ocelot.json", optional: false, reloadOnChange: true);

builder.Services
.AddOcelot(builder.Configuration)
.AddCustomLoadBalancer((route, serviceDiscovery) =>
new QueryBasedLoadBalancer(serviceDiscovery));


builder.Services
.AddHttpClient("ocelot")
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
{
ServerCertificateCustomValidationCallback =
HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
});

var clientAddress = builder.Configuration["ClientAddress"]
?? throw new InvalidOperationException("ClientAddress is not configured.");

builder.Services.AddCors(options =>
{
options.AddPolicy("ClientPolicy", policy =>
{
policy
.WithOrigins(clientAddress)
.AllowAnyHeader()
.AllowAnyMethod();
});
});

var app = builder.Build();

app.MapDefaultEndpoints();
app.UseCors("ClientPolicy");

await app.UseOcelot();
app.Run();
38 changes: 38 additions & 0 deletions ApiGateway/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:21053",
"sslPort": 44384
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5194",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7141;http://localhost:5194",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
8 changes: 8 additions & 0 deletions ApiGateway/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
14 changes: 14 additions & 0 deletions ApiGateway/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"ClientAddress": "https://localhost:7282",
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Ocelot": "Debug"
}
},
"GlobalConfiguration": {
"BaseUrl": "https://localhost:8095"
},
"AllowedHosts": "*"
}
29 changes: 29 additions & 0 deletions ApiGateway/ocelot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"Generators": [ "generator-1", "generator-2", "generator-3" ],
"Routes": [
{
"DownstreamPathTemplate": "/contracts/vehicle",
"DownstreamScheme": "https",
"UpstreamPathTemplate": "/contracts/vehicle",
"UpstreamHttpMethod": [ "Get" ],
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 8090
},
{
"Host": "localhost",
"Port": 8091
},
{
"Host": "localhost",
"Port": 8092
}
],
"LoadBalancerOptions": {
"Type": "QueryBasedLoadBalancer"
}
}
],
"GlobalConfiguration": {}
}
33 changes: 33 additions & 0 deletions Aspire.AppHost/AppHost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var builder = DistributedApplication.CreateBuilder(args);
var redis = builder.AddRedis("cache").WithRedisInsight();

var generator0 = builder.AddProject<Projects.Server>("back-0")
.WithEndpoint("https", endpoint => endpoint.Port = 8090)
.WithReference(redis)
.WaitFor(redis);

var generator1 = builder.AddProject<Projects.Server>("back-1")
.WithEndpoint("https", endpoint => endpoint.Port = 8091)
.WithReference(redis)
.WaitFor(redis);

var generator2 = builder.AddProject<Projects.Server>("back-2")
.WithEndpoint("https", endpoint => endpoint.Port = 8092)
.WithReference(redis)
.WaitFor(redis);

var gateway = builder.AddProject<Projects.ApiGateway>("gateway")
.WithEndpoint("https", endpoint => endpoint.Port = 8095)
.WithReference(generator0)
.WithReference(generator1)
.WithReference(generator2)
.WithExternalHttpEndpoints()
.WaitFor(generator0)
.WaitFor(generator1)
.WaitFor(generator2);

builder.AddProject<Projects.Client_Wasm>("front")
.WithReference(gateway)
.WaitFor(gateway);

builder.Build().Run();
24 changes: 24 additions & 0 deletions Aspire.AppHost/Aspire.AppHost.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>332a680f-f1c5-49c8-a258-12e527af6b5e</UserSecretsId>
</PropertyGroup>

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

<ItemGroup>
<ProjectReference Include="..\ApiGateway\ApiGateway.csproj" />
<ProjectReference Include="..\Server\Server.csproj" />
<ProjectReference Include="..\Client.Wasm\Client.Wasm.csproj" />
</ItemGroup>

</Project>
29 changes: 29 additions & 0 deletions Aspire.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:17077;http://localhost:15131",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21228",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22147"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15131",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19273",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20035"
}
}
}
}
8 changes: 8 additions & 0 deletions Aspire.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.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"
}
}
}
22 changes: 22 additions & 0 deletions Aspire.ServiceDefaults/Aspire.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="9.9.0" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="9.5.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>
Loading
Loading