Compare commits
31 Commits
9a12643eb6
...
feat/clien
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9628b46ba0 | ||
|
|
1f8142852e | ||
|
|
bdd78be66c | ||
|
|
470902911e | ||
|
|
3f7ebdb632 | ||
|
|
23ef1a5797 | ||
|
|
4a7f2a41fa | ||
|
|
5f9e716ca6 | ||
|
|
91c8b98f44 | ||
|
|
10fc56b262 | ||
|
|
71368e5c85 | ||
|
|
fb649a5c68 | ||
|
|
f4abac1103 | ||
|
|
4c8e9be695 | ||
|
|
b190e4f5e9 | ||
|
|
4a1b221478 | ||
|
|
475acc0a56 | ||
|
|
f8dd16454f | ||
|
|
8cad1df95d | ||
|
|
4ee79d6cd8 | ||
|
|
c0c0650fee | ||
|
|
73059d4554 | ||
|
|
e774afc85e | ||
|
|
1fc4570210 | ||
| b71ea7d346 | |||
| 3764fdaf01 | |||
| 5e7287bf86 | |||
| 9992086e48 | |||
| 40019bf693 | |||
| 4b9e577d41 | |||
| 4e6cb20dc2 |
5
ReC.sln
5
ReC.sln
@@ -15,6 +15,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReC.Application", "src\ReC.
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReC.Client", "src\ReC.Client\ReC.Client.csproj", "{DA3A6BDD-8045-478F-860B-D1F0EB97F02B}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReC.Client", "src\ReC.Client\ReC.Client.csproj", "{DA3A6BDD-8045-478F-860B-D1F0EB97F02B}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8EC462FD-D22E-90A8-E5CE-7E832BA40C5D}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
assets\icon.png = assets\icon.png
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
|||||||
BIN
assets/icon.png
Normal file
BIN
assets/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.1 KiB |
@@ -1,56 +1,78 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using NLog;
|
||||||
|
using NLog.Web;
|
||||||
using ReC.API.Middleware;
|
using ReC.API.Middleware;
|
||||||
using ReC.Application;
|
using ReC.Application;
|
||||||
using ReC.Infrastructure;
|
using ReC.Infrastructure;
|
||||||
|
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var logger = LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
|
||||||
|
logger.Info("Logging initialized!");
|
||||||
|
|
||||||
var config = builder.Configuration;
|
try
|
||||||
|
|
||||||
// Add services to the container.
|
|
||||||
builder.Services.AddRecServices(options =>
|
|
||||||
{
|
{
|
||||||
options.LuckyPennySoftwareLicenseKey = builder.Configuration["LuckyPennySoftwareLicenseKey"];
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
options.ConfigureRecActions(config.GetSection("RecAction"));
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.Services.AddRecInfrastructure(options =>
|
builder.Logging.SetMinimumLevel(LogLevel.Trace);
|
||||||
{
|
|
||||||
options.ConfigureDbContext((provider, opt) =>
|
if (!builder.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
var cnnStr = builder.Configuration.GetConnectionString("Default")
|
builder.Logging.ClearProviders();
|
||||||
?? throw new InvalidOperationException("Connection string is not found.");
|
builder.Host.UseNLog();
|
||||||
|
}
|
||||||
|
|
||||||
var logger = provider.GetRequiredService<ILogger<RecDbContext>>();
|
var config = builder.Configuration;
|
||||||
opt.UseSqlServer(cnnStr)
|
|
||||||
.LogTo(log => logger.LogInformation("{log}", log), LogLevel.Trace)
|
// Add services to the container.
|
||||||
.EnableSensitiveDataLogging()
|
builder.Services.AddRecServices(options =>
|
||||||
.EnableDetailedErrors();
|
{
|
||||||
|
options.LuckyPennySoftwareLicenseKey = builder.Configuration["LuckyPennySoftwareLicenseKey"];
|
||||||
|
options.ConfigureRecActions(config.GetSection("RecAction"));
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddRecInfrastructure(options =>
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
{
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
options.ConfigureDbContext((provider, opt) =>
|
||||||
builder.Services.AddSwaggerGen();
|
{
|
||||||
|
var cnnStr = builder.Configuration.GetConnectionString("Default")
|
||||||
|
?? throw new InvalidOperationException("Connection string is not found.");
|
||||||
|
|
||||||
var app = builder.Build();
|
var logger = provider.GetRequiredService<ILogger<RecDbContext>>();
|
||||||
|
opt.UseSqlServer(cnnStr)
|
||||||
|
.LogTo(log => logger.LogInformation("{log}", log), LogLevel.Trace)
|
||||||
|
.EnableSensitiveDataLogging()
|
||||||
|
.EnableDetailedErrors();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
|
builder.Services.AddSwaggerGen();
|
||||||
|
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
#pragma warning disable CS0618
|
#pragma warning disable CS0618
|
||||||
app.UseMiddleware<ExceptionHandlingMiddleware>();
|
app.UseMiddleware<ExceptionHandlingMiddleware>();
|
||||||
#pragma warning restore CS0618
|
#pragma warning restore CS0618
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
app.MapControllers();
|
||||||
|
|
||||||
|
app.Run();
|
||||||
}
|
}
|
||||||
|
catch(Exception ex)
|
||||||
app.UseHttpsRedirection();
|
{
|
||||||
|
logger.Error(ex, "Stopped program because of exception");
|
||||||
app.UseAuthorization();
|
throw;
|
||||||
|
}
|
||||||
app.MapControllers();
|
|
||||||
|
|
||||||
app.Run();
|
|
||||||
17
src/ReC.API/Properties/PublishProfiles/IISProfile.pubxml
Normal file
17
src/ReC.API/Properties/PublishProfiles/IISProfile.pubxml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
|
||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<WebPublishMethod>Package</WebPublishMethod>
|
||||||
|
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
|
||||||
|
<LastUsedPlatform>Any CPU</LastUsedPlatform>
|
||||||
|
<SiteUrlToLaunchAfterPublish />
|
||||||
|
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
|
||||||
|
<ExcludeApp_Data>false</ExcludeApp_Data>
|
||||||
|
<ProjectGuid>420218ad-3c27-4003-9a84-36c92352f175</ProjectGuid>
|
||||||
|
<DesktopBuildPackageLocation>P:\Install .Net\0 DD - Smart UP\ReC\API\$(Version)\Rec.API.zip</DesktopBuildPackageLocation>
|
||||||
|
<PackageAsSingleFile>true</PackageAsSingleFile>
|
||||||
|
<DeployIisAppPath>Rec.API</DeployIisAppPath>
|
||||||
|
<_TargetId>IISWebDeployPackage</_TargetId>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
@@ -1,14 +1,27 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<PackageId>ReC.API</PackageId>
|
||||||
|
<Authors>Digital Data GmbH</Authors>
|
||||||
|
<Company>Digital Data GmbH</Company>
|
||||||
|
<Product>ReC.API</Product>
|
||||||
|
<PackageIcon>Assets\icon.ico</PackageIcon>
|
||||||
|
<PackageTags>digital data rest-caller rec api</PackageTags>
|
||||||
|
<Version>1.0.0-beta</Version>
|
||||||
|
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
||||||
|
<FileVersion>1.0.0.0</FileVersion>
|
||||||
|
<InformationalVersion>1.0.0-beta</InformationalVersion>
|
||||||
|
<Copyright>Copyright © 2025 Digital Data GmbH. All rights reserved.</Copyright>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.11" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.11" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||||
|
<PackageReference Include="NLog" Version="5.2.5" />
|
||||||
|
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -14,5 +14,56 @@
|
|||||||
"MaxConcurrentInvocations": 5
|
"MaxConcurrentInvocations": 5
|
||||||
},
|
},
|
||||||
"AddedWho": "ReC.API",
|
"AddedWho": "ReC.API",
|
||||||
"FakeProfileId": 2
|
"FakeProfileId": 2,
|
||||||
|
"NLog": {
|
||||||
|
"throwConfigExceptions": true,
|
||||||
|
"variables": {
|
||||||
|
"logDirectory": "E:\\LogFiles\\Digital Data\\Rec.API",
|
||||||
|
"logFileNamePrefix": "${shortdate}.Rec.API"
|
||||||
|
},
|
||||||
|
"targets": {
|
||||||
|
"infoLogs": {
|
||||||
|
"type": "File",
|
||||||
|
"fileName": "${logDirectory}\\${logFileNamePrefix}-Info.log",
|
||||||
|
"maxArchiveDays": 30
|
||||||
|
},
|
||||||
|
"warningLogs": {
|
||||||
|
"type": "File",
|
||||||
|
"fileName": "${logDirectory}\\${logFileNamePrefix}-Warning.log",
|
||||||
|
"maxArchiveDays": 30
|
||||||
|
},
|
||||||
|
"errorLogs": {
|
||||||
|
"type": "File",
|
||||||
|
"fileName": "${logDirectory}\\${logFileNamePrefix}-Error.log",
|
||||||
|
"maxArchiveDays": 30
|
||||||
|
},
|
||||||
|
"criticalLogs": {
|
||||||
|
"type": "File",
|
||||||
|
"fileName": "${logDirectory}\\${logFileNamePrefix}-Critical.log",
|
||||||
|
"maxArchiveDays": 30
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rules": [
|
||||||
|
{
|
||||||
|
"logger": "*",
|
||||||
|
"level": "Info",
|
||||||
|
"writeTo": "infoLogs"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"logger": "*",
|
||||||
|
"level": "Warn",
|
||||||
|
"writeTo": "warningLogs"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"logger": "*",
|
||||||
|
"level": "Error",
|
||||||
|
"writeTo": "errorLogs"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"logger": "*",
|
||||||
|
"level": "Fatal",
|
||||||
|
"writeTo": "criticalLogs"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
41
src/ReC.Client/DependencyInjection.cs
Normal file
41
src/ReC.Client/DependencyInjection.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
#if NETFRAMEWORK
|
||||||
|
using System;
|
||||||
|
using System.Net.Http;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace ReC.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides extension methods for setting up the ReC client in an <see cref="IServiceCollection"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static class DependencyInjection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Adds and configures the <see cref="HttpClient"/> for the <see cref="ReCClient"/> to the specified <see cref="IServiceCollection"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
|
||||||
|
/// <param name="apiUri">The base URI of the ReC API.</param>
|
||||||
|
/// <returns>An <see cref="IHttpClientBuilder"/> that can be used to configure the client.</returns>
|
||||||
|
public static IHttpClientBuilder AddRecClient(this IServiceCollection services, string apiUri)
|
||||||
|
{
|
||||||
|
services.AddScoped<ReCClient>();
|
||||||
|
return services.AddHttpClient(ReCClient.ClientName, client =>
|
||||||
|
{
|
||||||
|
client.BaseAddress = new Uri(apiUri);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds and configures the <see cref="HttpClient"/> for the <see cref="ReCClient"/> to the specified <see cref="IServiceCollection"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
|
||||||
|
/// <param name="configureClient">An action to configure the <see cref="HttpClient"/>.</param>
|
||||||
|
/// <returns>An <see cref="IHttpClientBuilder"/> that can be used to configure the client.</returns>
|
||||||
|
public static IHttpClientBuilder AddRecClient(this IServiceCollection services, Action<HttpClient> configureClient)
|
||||||
|
{
|
||||||
|
services.AddScoped<ReCClient>();
|
||||||
|
return services.AddHttpClient(ReCClient.ClientName, configureClient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,10 +2,36 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net462;net8.0</TargetFrameworks>
|
<TargetFrameworks>net462;net8.0</TargetFrameworks>
|
||||||
|
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(MSBuildProjectName).xml</DocumentationFile>
|
||||||
|
<PackageId>ReC.Client</PackageId>
|
||||||
|
<Authors>Digital Data GmbH</Authors>
|
||||||
|
<Company>Digital Data GmbH</Company>
|
||||||
|
<Product>ReC.Client</Product>
|
||||||
|
<Copyright>Copyright 2025</Copyright>
|
||||||
|
<PackageIcon>icon.png</PackageIcon>
|
||||||
|
<RepositoryUrl>http://git.dd:3000/AppStd/Rec.git</RepositoryUrl>
|
||||||
|
<PackageTags>digital data rec api</PackageTags>
|
||||||
|
<Version>1.0.0-beta</Version>
|
||||||
|
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
||||||
|
<FileVersion>1.0.0.0</FileVersion>
|
||||||
|
<Description>Client-Bibliothek für die Interaktion mit der ReC.API, die typisierten HTTP-Zugriff und DI-Integration bietet.</Description>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(TargetFramework)' != 'net462'">
|
<PropertyGroup Condition="'$(TargetFramework)' != 'net462'">
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\..\assets\icon.png">
|
||||||
|
<Pack>True</Pack>
|
||||||
|
<PackagePath>\</PackagePath>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
||||||
|
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
124
src/ReC.Client/ReCClient.cs
Normal file
124
src/ReC.Client/ReCClient.cs
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
#if NETFRAMEWORK
|
||||||
|
using System;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace ReC.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A client for interacting with the ReC API.
|
||||||
|
/// </summary>
|
||||||
|
public class ReCClient
|
||||||
|
{
|
||||||
|
private readonly HttpClient _http;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A unique name for the HttpClient used by the ReCClient.
|
||||||
|
/// </summary>
|
||||||
|
public static readonly string ClientName = Guid.NewGuid().ToString();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ReCClient"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="httpClientFactory">The factory to create HttpClients.</param>
|
||||||
|
public ReCClient(IHttpClientFactory httpClientFactory)
|
||||||
|
{
|
||||||
|
_http = httpClientFactory.CreateClient(ClientName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Asynchronously invokes a ReC action for a specific profile.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This method sends a POST request to the <c>api/RecAction/invoke/{profileId}</c> endpoint.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="profileId">The ID of the profile to invoke the action for.</param>
|
||||||
|
/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
|
||||||
|
/// <returns>A <see cref="Task{TResult}"/> that represents the asynchronous operation. The task result is <see langword="true"/> if the request was successful; otherwise, <see langword="false"/>.</returns>
|
||||||
|
public async Task<bool> InvokeRecActionAsync(int profileId, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var resp = await _http.PostAsync($"api/RecAction/invoke/{profileId}", content: null, cancellationToken);
|
||||||
|
return resp.IsSuccessStatusCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Synchronously invokes a ReC action for a specific profile.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This method sends a POST request to the <c>api/RecAction/invoke/{profileId}</c> endpoint.
|
||||||
|
/// This is the synchronous version of <see cref="InvokeRecActionAsync(int, CancellationToken)"/>.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="profileId">The ID of the profile to invoke the action for.</param>
|
||||||
|
/// <returns><see langword="true"/> if the request was successful; otherwise, <see langword="false"/>.</returns>
|
||||||
|
[Obsolete("Use InvokeRecActionAsync instead to avoid potential deadlocks and improve performance.")]
|
||||||
|
public bool InvokeRecAction(int profileId)
|
||||||
|
{
|
||||||
|
var resp = _http.PostAsync($"api/RecAction/invoke/{profileId}", content: null).GetAwaiter().GetResult();
|
||||||
|
return resp.IsSuccessStatusCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Static
|
||||||
|
private static readonly IServiceCollection Services = new ServiceCollection();
|
||||||
|
|
||||||
|
#if NET8_0_OR_GREATER
|
||||||
|
private static IServiceProvider? Provider = null;
|
||||||
|
#else
|
||||||
|
private static IServiceProvider Provider = null;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Configures and builds the static <see cref="IServiceProvider"/> for creating <see cref="ReCClient"/> instances.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This method should only be called once during application startup.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="apiUri">The base URI of the ReC API.</param>
|
||||||
|
/// <exception cref="InvalidOperationException">Thrown if the static provider has already been built.</exception>
|
||||||
|
[Obsolete("Use a local service collection instead of the static provider.")]
|
||||||
|
public static void BuildStaticClient(string apiUri)
|
||||||
|
{
|
||||||
|
if(Provider != null)
|
||||||
|
throw new InvalidOperationException("Static Provider is already built.");
|
||||||
|
|
||||||
|
Services.AddRecClient(apiUri);
|
||||||
|
Provider = Services.BuildServiceProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Configures and builds the static <see cref="IServiceProvider"/> for creating <see cref="ReCClient"/> instances.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This method should only be called once during application startup.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="configureClient">An action to configure the <see cref="HttpClient"/>.</param>
|
||||||
|
/// <exception cref="InvalidOperationException">Thrown if the static provider has already been built.</exception>
|
||||||
|
[Obsolete("Use a local service collection instead of the static provider.")]
|
||||||
|
public static void BuildStaticClient(Action<HttpClient> configureClient)
|
||||||
|
{
|
||||||
|
if (Provider != null)
|
||||||
|
throw new InvalidOperationException("Static Provider is already built.");
|
||||||
|
|
||||||
|
Services.AddRecClient(configureClient);
|
||||||
|
Provider = Services.BuildServiceProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new <see cref="ReCClient"/> instance using the statically configured provider.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A new instance of the <see cref="ReCClient"/>.</returns>
|
||||||
|
/// <exception cref="InvalidOperationException">Thrown if <see cref="BuildStaticClient(string)"/> has not been called yet.</exception>
|
||||||
|
[Obsolete("Use a local service collection instead of the static provider.")]
|
||||||
|
public static ReCClient Create()
|
||||||
|
{
|
||||||
|
if (Provider == null)
|
||||||
|
throw new InvalidOperationException("Static Provider is not built. Call BuildStaticClient first.");
|
||||||
|
|
||||||
|
return Provider.GetRequiredService<ReCClient>();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user