Skip to content

Commit 832c1e7

Browse files
committed
Ported to .Net 8
1 parent 2e971d2 commit 832c1e7

File tree

91 files changed

+1795
-1980
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1795
-1980
lines changed

Exchange.Rates.CoinCap.OpenApi/.dockerignore

-25
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using Microsoft.Extensions.Configuration;
22
using Microsoft.Extensions.DependencyInjection;
33

4-
namespace Exchange.Rates.CoinCap.OpenApi.Contracts
4+
namespace Exchange.Rates.CoinCap.OpenApi.Contracts;
5+
6+
public interface IServiceRegistration
57
{
6-
public interface IServiceRegistration
7-
{
8-
void Register(IServiceCollection services, IConfiguration configuration);
9-
}
8+
void Register(IServiceCollection services, IConfiguration configuration);
109
}
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,78 @@
1-
using Exchange.Rates.Contracts.Messages;
2-
using Exchange.Rates.CoinCap.OpenApi.Models;
1+
using Exchange.Rates.CoinCap.OpenApi.Models;
2+
using Exchange.Rates.Contracts.Messages;
33
using MassTransit;
44
using Microsoft.AspNetCore.Http;
55
using Microsoft.AspNetCore.Mvc;
66
using Microsoft.Extensions.Logging;
7-
using System.Threading.Tasks;
87
using System;
8+
using System.Threading.Tasks;
99

10-
namespace Exchange.Rates.CoinCap.OpenApi.Controllers
11-
{
12-
[ApiController]
13-
[Produces("application/json")]
14-
[Route("api/[controller]")]
15-
public class ExchangeRatesCoinCapController : ControllerBase
16-
{
17-
private readonly ILogger<ExchangeRatesCoinCapController> _logger;
18-
private readonly IRequestClient<SubmitCoinCapAssetId> _submitCoinCapAssetIdRequestClient;
10+
namespace Exchange.Rates.CoinCap.OpenApi.Controllers;
1911

20-
public ExchangeRatesCoinCapController(ILogger<ExchangeRatesCoinCapController> logger,
21-
IRequestClient<SubmitCoinCapAssetId> submitCoinCapAssetIdRequestClient)
22-
{
23-
_logger = logger;
24-
_submitCoinCapAssetIdRequestClient = submitCoinCapAssetIdRequestClient;
25-
}
12+
[ApiController]
13+
[Produces("application/json")]
14+
[Route("api/[controller]")]
15+
public class ExchangeRatesCoinCapController(
16+
ILogger<ExchangeRatesCoinCapController> logger,
17+
IRequestClient<ISubmitCoinCapAssetId> submitCoinCapAssetIdRequestClient)
18+
: ControllerBase
19+
{
2620

27-
/// <summary>
28-
/// Crypto AssetInfo endpoint
29-
/// </summary>
30-
/// <remarks>
31-
/// The asset price calculated by collecting ticker data from exchanges. Example Id: bitcoin
32-
/// </remarks>
33-
/// <param name="model">Unique identifier for asset. Ex: bitcoin</param>
34-
/// <returns></returns>
35-
/// <response code="200">Returned if everything is ok</response>
36-
/// <response code="400">Returned if something went wrong</response>
37-
[HttpGet("assetinfo")]
38-
[ProducesResponseType(StatusCodes.Status200OK)]
39-
[ProducesResponseType(StatusCodes.Status400BadRequest)]
40-
public async Task<IActionResult> AssetInfo([FromQuery] AssetIdSubmissionModel model)
41-
{
42-
try
43-
{
44-
if (!ModelState.IsValid)
45-
{
46-
_logger.LogError("Invalid Model");
47-
return BadRequest(ModelState);
48-
}
21+
/// <summary>
22+
/// Crypto AssetInfo endpoint
23+
/// </summary>
24+
/// <remarks>
25+
/// The asset price calculated by collecting ticker data from exchanges. Example Id: bitcoin
26+
/// </remarks>
27+
/// <param name="model">Unique identifier for asset. Ex: bitcoin</param>
28+
/// <returns></returns>
29+
/// <response code="200">Returned if everything is ok</response>
30+
/// <response code="400">Returned if something went wrong</response>
31+
[HttpGet("assetinfo")]
32+
[ProducesResponseType(StatusCodes.Status200OK)]
33+
[ProducesResponseType(StatusCodes.Status400BadRequest)]
34+
public async Task<IActionResult> AssetInfo([FromQuery] AssetIdSubmissionModel model)
35+
{
36+
try
37+
{
38+
if (!ModelState.IsValid)
39+
{
40+
logger.LogError("Invalid Model");
41+
return BadRequest(ModelState);
42+
}
4943

50-
// https://masstransit-project.com/usage/requests.html#request-client
51-
var (accepted, rejected) = await _submitCoinCapAssetIdRequestClient.GetResponse<CoinCapAssetAccepted, CoinCapAssetRejected>(new
52-
{
53-
EventId = NewId.NextGuid(),
54-
InVar.Timestamp,
55-
model.Id
56-
}).ConfigureAwait(false);
44+
// https://masstransit-project.com/usage/requests.html#request-client
45+
var (accepted, rejected) = await submitCoinCapAssetIdRequestClient.GetResponse<ICoinCapAssetAccepted, ICoinCapAssetRejected>(new
46+
{
47+
EventId = NewId.NextGuid(),
48+
InVar.Timestamp,
49+
model.Id
50+
}).ConfigureAwait(false);
5751

58-
if (accepted.IsCompletedSuccessfully)
59-
{
60-
var response = await accepted.ConfigureAwait(false);
61-
return Ok(response.Message.AssetData);
62-
}
52+
if (accepted.IsCompletedSuccessfully)
53+
{
54+
var response = await accepted.ConfigureAwait(false);
55+
return Ok(response.Message.AssetData);
56+
}
6357

64-
if (accepted.IsCompleted)
65-
{
66-
await accepted.ConfigureAwait(false);
67-
var errMessage = "Asset Id was not accepted. Please check the syntax!";
68-
_logger.LogError(errMessage);
69-
return Problem(errMessage);
70-
}
71-
else
72-
{
73-
var response = await rejected.ConfigureAwait(false);
74-
_logger.LogError(response.Message.Reason);
75-
return BadRequest(response.Message);
76-
}
77-
}
78-
catch (Exception ex)
79-
{
80-
_logger.LogError(ex.Message);
81-
return BadRequest(ex.Message);
82-
}
83-
}
58+
if (accepted.IsCompleted)
59+
{
60+
await accepted.ConfigureAwait(false);
61+
var errMessage = "Asset Id was not accepted. Please check the syntax!";
62+
logger.LogError(errMessage);
63+
return Problem(errMessage);
64+
}
65+
else
66+
{
67+
var response = await rejected.ConfigureAwait(false);
68+
logger.LogError(response.Message.Reason);
69+
return BadRequest(response.Message);
70+
}
71+
}
72+
catch (Exception ex)
73+
{
74+
logger.LogError(ex, ex.Message);
75+
return BadRequest(ex.Message);
8476
}
77+
}
8578
}

Exchange.Rates.CoinCap.OpenApi/Dockerfile

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
1-
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
1+
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
22

3-
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
3+
# This stage is used when running from VS in fast mode (Default for Debug configuration)
4+
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
5+
USER app
46
WORKDIR /app
5-
EXPOSE 80
6-
EXPOSE 443
7+
EXPOSE 8080
8+
EXPOSE 8081
79

8-
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
10+
11+
# This stage is used to build the service project
12+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
13+
ARG BUILD_CONFIGURATION=Release
914
WORKDIR /src
1015
COPY ["Exchange.Rates.CoinCap.OpenApi/Exchange.Rates.CoinCap.OpenApi.csproj", "Exchange.Rates.CoinCap.OpenApi/"]
1116
COPY ["Exchange.Rates.Contracts/Exchange.Rates.Contracts.csproj", "Exchange.Rates.Contracts/"]
1217
COPY ["Exchange.Rates.Core/Exchange.Rates.Core.csproj", "Exchange.Rates.Core/"]
13-
RUN dotnet restore "Exchange.Rates.CoinCap.OpenApi/Exchange.Rates.CoinCap.OpenApi.csproj"
18+
RUN dotnet restore "./Exchange.Rates.CoinCap.OpenApi/Exchange.Rates.CoinCap.OpenApi.csproj"
1419
COPY . .
1520
WORKDIR "/src/Exchange.Rates.CoinCap.OpenApi"
16-
RUN dotnet build "Exchange.Rates.CoinCap.OpenApi.csproj" -c Release -o /app/build
21+
RUN dotnet build "./Exchange.Rates.CoinCap.OpenApi.csproj" -c $BUILD_CONFIGURATION -o /app/build
1722

23+
# This stage is used to publish the service project to be copied to the final stage
1824
FROM build AS publish
19-
RUN dotnet publish "Exchange.Rates.CoinCap.OpenApi.csproj" -c Release -o /app/publish
25+
ARG BUILD_CONFIGURATION=Release
26+
RUN dotnet publish "./Exchange.Rates.CoinCap.OpenApi.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
2027

28+
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
2129
FROM base AS final
2230
WORKDIR /app
2331
COPY --from=publish /app/publish .

Exchange.Rates.CoinCap.OpenApi/Exchange.Rates.CoinCap.OpenApi.csproj

+10-19
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,47 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFramework>net8.0</TargetFramework>
44
<UserSecretsId>f6926b47-26fe-4da8-8974-b521980fb317</UserSecretsId>
55
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
66
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
77
</PropertyGroup>
8-
98
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
109
<NoWarn>1701;1702;1705;IDE0063;IDE0066;CS1591</NoWarn>
1110
<DocumentationFile>bin\Debug\netcoreapp3.1\Exchange.Rates.CoinCap.OpenApi.xml</DocumentationFile>
1211
<OutputPath>bin\Debug</OutputPath>
1312
</PropertyGroup>
14-
1513
<ItemGroup>
1614
<PackageReference Include="MassTransit.AspNetCore" Version="7.3.1" />
17-
<PackageReference Include="MassTransit.RabbitMQ" Version="8.0.5" />
18-
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.7" />
19-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
20-
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.7" />
21-
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
22-
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.16.1" />
23-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
24-
<PackageReference Include="Serilog.AspNetCore" Version="6.0.0" />
25-
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.2" />
26-
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.3.2" />
15+
<PackageReference Include="MassTransit.RabbitMQ" Version="8.2.5" />
16+
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.10" />
17+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
18+
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.10" />
19+
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
20+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
21+
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
22+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.8.1" />
23+
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.8.1" />
2724
</ItemGroup>
28-
2925
<ItemGroup>
3026
<Folder Include="Log\" />
3127
</ItemGroup>
32-
3328
<ItemGroup>
3429
<ProjectReference Include="..\Exchange.Rates.Contracts\Exchange.Rates.Contracts.csproj" />
3530
<ProjectReference Include="..\Exchange.Rates.Core\Exchange.Rates.Core.csproj" />
3631
</ItemGroup>
37-
3832
<ItemGroup>
3933
<Content Update="appsettings.json">
4034
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
4135
</Content>
4236
</ItemGroup>
43-
4437
<ItemGroup>
4538
<None Update="Infrastructure\Certificate\cert-aspnetcore.pfx">
4639
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
4740
</None>
4841
</ItemGroup>
49-
5042
<PropertyGroup>
5143
<GenerateDocumentationFile>true</GenerateDocumentationFile>
5244
</PropertyGroup>
53-
5445
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
5546
<NoWarn>1701;1702;CS1591</NoWarn>
5647
</PropertyGroup>
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
using Microsoft.Extensions.Configuration;
1+
using Exchange.Rates.CoinCap.OpenApi.Contracts;
2+
using Microsoft.Extensions.Configuration;
23
using Microsoft.Extensions.DependencyInjection;
3-
using Exchange.Rates.CoinCap.OpenApi.Contracts;
44
using System;
55
using System.Linq;
66

7-
namespace Exchange.Rates.CoinCap.OpenApi.Extensions
7+
namespace Exchange.Rates.CoinCap.OpenApi.Extensions;
8+
9+
internal static class ServiceRegistrationExtension
810
{
9-
internal static class ServiceRegistrationExtension
10-
{
11-
public static void AddServicesInAssembly(this IServiceCollection services, IConfiguration configuration)
12-
{
13-
var appServices = typeof(Startup).Assembly.DefinedTypes
14-
.Where(x => typeof(IServiceRegistration)
15-
.IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract)
16-
.Select(Activator.CreateInstance)
17-
.Cast<IServiceRegistration>().ToList();
18-
appServices.ForEach(svc => svc.Register(services, configuration));
19-
}
20-
}
11+
public static void AddServicesInAssembly(this IServiceCollection services, IConfiguration configuration)
12+
{
13+
var appServices = typeof(Startup).Assembly.DefinedTypes
14+
.Where(x => typeof(IServiceRegistration)
15+
.IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract)
16+
.Select(Activator.CreateInstance)
17+
.Cast<IServiceRegistration>().ToList();
18+
appServices.ForEach(svc => svc.Register(services, configuration));
19+
}
2120
}
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
using Microsoft.OpenApi.Models;
22
using Swashbuckle.AspNetCore.SwaggerGen;
3+
using System;
34
using System.Collections.Generic;
45
using System.Linq;
5-
using System;
66

7-
namespace Exchange.Rates.CoinCap.OpenApi.Filters
7+
namespace Exchange.Rates.CoinCap.OpenApi.Filters;
8+
9+
/// <summary>
10+
/// Corresponding to Controller's API document description information
11+
/// </summary>
12+
public class SwaggerDocumentFilter : IDocumentFilter
813
{
9-
/// <summary>
10-
/// Corresponding to Controller's API document description information
11-
/// </summary>
12-
public class SwaggerDocumentFilter : IDocumentFilter
13-
{
14-
private const string DOCS_URI = "https://docs.coincap.io/";
14+
private const string DOCS_URI = "https://docs.coincap.io/";
1515

16-
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
17-
{
18-
var tags = new List<OpenApiTag>
19-
{
20-
new()
21-
{
22-
Name = "ExchangeRatesCoinCap",
23-
Description = "CoinCap API 2.0",
24-
ExternalDocs = new OpenApiExternalDocs
25-
{
26-
Description = "Read more",
27-
Url = new Uri(DOCS_URI)
28-
}
29-
}
30-
};
16+
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
17+
{
18+
var tags = new List<OpenApiTag>
19+
{
20+
new()
21+
{
22+
Name = "ExchangeRatesCoinCap",
23+
Description = "CoinCap API 2.0",
24+
ExternalDocs = new OpenApiExternalDocs
25+
{
26+
Description = "Read more",
27+
Url = new Uri(DOCS_URI)
28+
}
29+
}
30+
};
3131

32-
// Sort in ascending order by AssemblyName
33-
swaggerDoc.Tags = tags.OrderBy(x => x.Name).ToList();
34-
}
35-
}
32+
// Sort in ascending order by AssemblyName
33+
swaggerDoc.Tags = tags.OrderBy(x => x.Name).ToList();
34+
}
3635
}

0 commit comments

Comments
 (0)