Initial work on getting minimal API to work
This commit is contained in:
@@ -13,4 +13,8 @@
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AS1024.GeoFeed.Core\AS1024.GeoFeed.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
31
AS1024.GeoFeed.MinimalAPI/GeoFeedAoTProvider.cs
Normal file
31
AS1024.GeoFeed.MinimalAPI/GeoFeedAoTProvider.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using AS1024.GeoFeed.Core.GeoFeedProviders;
|
||||
using AS1024.GeoFeed.Core.Interfaces;
|
||||
using AS1024.GeoFeed.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization.Metadata;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AS1024.GeoFeed.MinimalAPI
|
||||
{
|
||||
internal class NetboxAoTGeoFeedProvider : NetBoxGeoFeedProvider, IGeoFeedProvider
|
||||
{
|
||||
private readonly JsonSerializerOptions appJsonSerializer;
|
||||
|
||||
public NetboxAoTGeoFeedProvider(IConfiguration configuration,
|
||||
ILogger<NetBoxGeoFeedProvider> logger,
|
||||
IHttpClientFactory httpClientFactory)
|
||||
: base(configuration, logger, httpClientFactory)
|
||||
{
|
||||
}
|
||||
|
||||
protected override NetboxData? DeserializeJsonData(string stringResult)
|
||||
{
|
||||
return JsonSerializer.Deserialize(stringResult, AppJsonSerializerContext.Default.NetboxData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,9 @@
|
||||
using AS1024.GeoFeed.Core.GeoFeedProviders;
|
||||
using AS1024.GeoFeed.Core.Interfaces;
|
||||
using AS1024.GeoFeed.Core.Tools;
|
||||
using AS1024.GeoFeed.Models;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace AS1024.GeoFeed.MinimalAPI
|
||||
@@ -7,12 +13,39 @@ namespace AS1024.GeoFeed.MinimalAPI
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateSlimBuilder(args);
|
||||
|
||||
builder.Services.AddTransient<IGeoFeedProvider, NetboxAoTGeoFeedProvider>();
|
||||
builder.Services.AddMemoryCache();
|
||||
builder.Services.AddLogging();
|
||||
builder.Services.AddHttpClient();
|
||||
builder.Services.ConfigureHttpJsonOptions(options => {
|
||||
options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
|
||||
});
|
||||
var app = builder.Build();
|
||||
var geoFeed = app.MapGroup("/geofeed.csv");
|
||||
var geoFeed = app.Map("/geofeed.csv", async (IGeoFeedProvider provider, ILogger<Program> logger) => {
|
||||
try
|
||||
{
|
||||
var results =
|
||||
await provider.GetGeoFeedData();
|
||||
return results.ToGeoFeedCsv();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"Error: {ex}");
|
||||
}
|
||||
|
||||
return "";
|
||||
});
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
|
||||
[JsonSerializable(typeof(NetboxData))]
|
||||
[JsonSerializable(typeof(Result))]
|
||||
[JsonSerializable(typeof(CustomFields))]
|
||||
[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.SnakeCaseLower)]
|
||||
internal partial class AppJsonSerializerContext : JsonSerializerContext
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user