Skip to content
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
2 changes: 1 addition & 1 deletion src/Jiban.Api/Controllers/RedisDebugController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Jiban.BaseCode.PermissionsCode;
using Jiban.Infrastructure;
using Jiban.Nswag;
using Jiban.Infrastructure.Nswag;
using JibanPermissions.Services;
using Microsoft.AspNetCore.Mvc;

Expand Down
2 changes: 1 addition & 1 deletion src/Jiban.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
app.UseSwaggerUI(options => options.SwaggerEndpoint("/openapi/v1.json", "Jiban API v1"));
app.UseSwaggerUI(options => options.SwaggerEndpoint("/openapi/v1.json", "Jiban Event v1"));
}

app.UseHttpsRedirection();
Expand Down
2 changes: 1 addition & 1 deletion src/Jiban.Domain/Jiban.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Jiban.Multitenant" Version="9.12.870" />
<PackageReference Include="Jiban.Multitenant" Version="9.12.872" />
</ItemGroup>

</Project>
4 changes: 0 additions & 4 deletions src/Jiban.Infrastructure/BaseUtil.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using Jiban.BaseCode.PermissionsCode;
using Jiban.Domain;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jiban.Infrastructure
Expand Down
22 changes: 6 additions & 16 deletions src/Jiban.Infrastructure/Configuration/InfraestructureExtension.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using Microsoft.Extensions.DependencyInjection;
using Jiban.BaseCode.PermissionsCode;
using Jiban.Infrastructure.HostedServices;
using Microsoft.Extensions.Configuration;
using Jiban.BaseCode.PermissionsCode;
using Jiban.Infrastructure.Nswag;
using Jiban.Infrastructure.Services;
using Polly.Extensions.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Polly;
using Jiban.Nswag;
using JibanPermissions.Services;
using Polly.Extensions.Http;

namespace Jiban.Infrastructure.Configuration
{
Expand All @@ -24,20 +23,11 @@ public static IServiceCollection AddJibanHostedServices(this IServiceCollection

public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, IConfiguration configuration)
{

services.AddScoped<IElectronicDocService, ElectronicDocService>();
services.AddScoped<ISriClient, SriClient>();
services.AddSingleton<ITokenAccessor, RuntimeTokenAccessor>();
services.AddTransient<DynamicJwtHandler>();

var baseUrl = configuration["NswagBaseUrl"];
if (string.IsNullOrWhiteSpace(baseUrl))
throw new InvalidOperationException("Missing env var: NswagBaseUrl");

services.AddHttpClient(string.Empty, client =>
{
client.BaseAddress = new Uri(baseUrl);
})
services.AddHttpClient<NswagConfiguration>()
.AddHttpMessageHandler<DynamicJwtHandler>()
.AddPolicyHandler(GetRetryPolicy())
.AddPolicyHandler(GetCircuitBreakerPolicy())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Jiban.Nswag;
using Jiban.Infrastructure.Nswag;

namespace Jiban.Infrastructure.HostedServices
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Jiban.BaseCode.PermissionsCode;

using Jiban.BaseCode.PermissionsCode;
using Jiban.Infrastructure.Nswag;
using Microsoft.Extensions.Logging;
using StackExchange.Redis;
using Jiban.Nswag;

namespace Jiban.Infrastructure.HostedServices
{
Expand Down
60 changes: 30 additions & 30 deletions src/Jiban.Infrastructure/Jiban.Infrastructure.csproj
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Library</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0-rc.2.25502.107" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0-rc.2.25502.107" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.0-rc.2.25502.107" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.0-rc.2.25502.107" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="10.0.0-rc.2.25502.107" />
<PackageReference Include="NSwag.MSBuild" Version="14.6.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Polly" Version="8.6.4" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0-rc.2.25502.107" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0-rc.2.25502.107" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.0-rc.2.25502.107" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.0-rc.2.25502.107" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="10.0.0-rc.2.25502.107" />
<PackageReference Include="NSwag.MSBuild" Version="14.6.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Polly" Version="8.6.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Jiban.Domain\Jiban.Domain.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Jiban.Domain\Jiban.Domain.csproj" />
</ItemGroup>

<PropertyGroup>
<NSwagDllPath>$(NuGetPackageRoot)nswag.msbuild\14.6.1\tools\Net100\dotnet-nswag.dll</NSwagDllPath>
</PropertyGroup>
<PropertyGroup>
<NSwagDllPath>$(NuGetPackageRoot)nswag.msbuild\14.6.1\tools\Net100\dotnet-nswag.dll</NSwagDllPath>
</PropertyGroup>

<!-- Run NSwag on real builds (kept) -->
<Target Name="NSwag" BeforeTargets="Build" Condition="'$(Configuration)' == 'Debug' and Exists('config.nswag')">
<Exec Command="dotnet exec &quot;$(NSwagDllPath)&quot; run config.nswag" ContinueOnError="true" />
</Target>
<!-- Run NSwag on real builds (kept) -->
<Target Name="NSwag" BeforeTargets="Build" Condition="'$(Configuration)' == 'Debug' and Exists('config.nswag') and !Exists('Nswag\Platform.cs')">
<Exec Command="dotnet exec &quot;$(NSwagDllPath)&quot; run config.nswag" ContinueOnError="true" />
</Target>

<!-- Design-time: run NSwag only if the generated file is missing; run only for real builds (not design-time) -->
<Target Name="NSwag_DesignTime" BeforeTargets="CoreCompile"
Condition="'$(Configuration)' == 'Debug' and Exists('config.nswag') and '$(DesignTimeBuild)' != 'true' and !Exists('Services\Platform.cs')">
<Message Importance="high" Text="NSwag: Generating client (design-time) because Services\Platform.cs is missing..." />
Condition="'$(Configuration)' == 'Debug' and Exists('config.nswag') and '$(DesignTimeBuild)' != 'true' and !Exists('Nswag\Platform.cs')">
<Message Importance="high" Text="NSwag: Generating client (design-time) because Nswag\Platform.cs is missing..." />
<Exec Command="dotnet exec &quot;$(NSwagDllPath)&quot; run config.nswag" ContinueOnError="false" />
</Target>

Expand Down
14 changes: 14 additions & 0 deletions src/Jiban.Infrastructure/Nswag/NswagBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Jiban.Infrastructure.Nswag
{
public class NswagBase
{
protected readonly NswagConfiguration _nswagConfiguration;
protected readonly HttpClient _httpClient;

public NswagBase(NswagConfiguration nswagConfiguration)
{
_nswagConfiguration = nswagConfiguration;
_httpClient = _nswagConfiguration._httpClient;
}
}
}
55 changes: 55 additions & 0 deletions src/Jiban.Infrastructure/Nswag/NswagConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Jiban.BaseCode.PermissionsCode;
using Microsoft.Extensions.Configuration;

namespace Jiban.Infrastructure.Nswag
{
/// <summary>
/// Provides configuration used for NSwag-generated API calls.
/// Contains the NSwag API base URL and the <see cref="HttpClient"/> used to make requests.
/// </summary>
public class NswagConfiguration
{
/// <summary>
/// Gets or sets the NSwag API base URL.
/// </summary>
/// <value>
/// The base URL read from configuration key "NswagBaseUrl". May be absolute or relative.
/// </value>
public string _baseUrl { get; set; }

/// <summary>
/// Gets or sets the <see cref="HttpClient"/> used to send requests to NSwag APIs.
/// </summary>
/// <value>An initialized <see cref="HttpClient"/>, typically provided by dependency injection.</value>
public HttpClient _httpClient { get; set; }

/// <summary>
/// Initializes a new instance of <see cref="NswagConfiguration"/>.
/// </summary>
/// <param name="httpClient">The <see cref="HttpClient"/> to use for API requests.</param>
/// <param name="configuration">Application configuration used to read the NSwag base URL (key "NswagBaseUrl").</param>
/// <remarks>
/// The constructor reads the "NswagBaseUrl" configuration value and assigns it to <see cref="_baseUrl"/>.
/// If the configuration key is missing or invalid an exception is thrown.
/// </remarks>
public NswagConfiguration(HttpClient httpClient, IConfiguration configuration)
{
_httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
if (configuration is null) throw new ArgumentNullException(nameof(configuration));

var baseUrl = configuration[JibanConstants.NswagBaseUrl];
if (string.IsNullOrWhiteSpace(baseUrl))
{
throw new InvalidOperationException($"Configuration value '{JibanConstants.NswagBaseUrl}' is missing or empty.");
}

if (!Uri.TryCreate(baseUrl, UriKind.Absolute, out var baseUri))
{
throw new InvalidOperationException($"Configuration value '{JibanConstants.NswagBaseUrl}' is not a valid absolute URI: '{baseUrl}'.");
}

_httpClient.BaseAddress = baseUri;
_baseUrl = baseUrl;
}
}
}
Loading
Loading