Browse Source

Update giraffe sample to .NET 6 alpha (#6891)

* Update giraffe sample to .NET 6

* Use WebApplication in Giraffe host

* Update Npgsql
Steffen Forkmann 3 years ago
parent
commit
be20753c93

+ 2 - 2
frameworks/FSharp/giraffe/README.md

@@ -14,7 +14,7 @@ This application tests Giraffe in 3 modes:
 
 
 **Platforms**
 **Platforms**
 
 
-* .NET 5 (Windows and Linux)
+* .NET 6 (Windows and Linux)
 
 
 **Web Servers**
 **Web Servers**
 
 
@@ -29,7 +29,7 @@ This application tests Giraffe in 3 modes:
 
 
 All source code is inside `Program.fs`.
 All source code is inside `Program.fs`.
 
 
-App listens for a signle command line argument to pick the desired JSON implementation:
+App listens for a single command line argument to pick the desired JSON implementation:
 
 
     - `system`: `System.Text.Json`
     - `system`: `System.Text.Json`
     - `utf8`: `Utf8Json`
     - `utf8`: `Utf8Json`

+ 2 - 2
frameworks/FSharp/giraffe/giraffe-newtonsoft.dockerfile

@@ -1,9 +1,9 @@
-FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
+FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
 WORKDIR /app
 WORKDIR /app
 COPY src/App .
 COPY src/App .
 RUN dotnet publish -c Release -o out
 RUN dotnet publish -c Release -o out
 
 
-FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime
+FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime
 ENV ASPNETCORE_URLS http://+:8080
 ENV ASPNETCORE_URLS http://+:8080
 WORKDIR /app
 WORKDIR /app
 COPY --from=build /app/out ./
 COPY --from=build /app/out ./

+ 2 - 2
frameworks/FSharp/giraffe/giraffe-utf8json.dockerfile

@@ -1,9 +1,9 @@
-FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
+FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
 WORKDIR /app
 WORKDIR /app
 COPY src/App .
 COPY src/App .
 RUN dotnet publish -c Release -o out
 RUN dotnet publish -c Release -o out
 
 
-FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime
+FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime
 ENV ASPNETCORE_URLS http://+:8080
 ENV ASPNETCORE_URLS http://+:8080
 WORKDIR /app
 WORKDIR /app
 COPY --from=build /app/out ./
 COPY --from=build /app/out ./

+ 2 - 2
frameworks/FSharp/giraffe/giraffe.dockerfile

@@ -1,9 +1,9 @@
-FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
+FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
 WORKDIR /app
 WORKDIR /app
 COPY src/App .
 COPY src/App .
 RUN dotnet publish -c Release -o out
 RUN dotnet publish -c Release -o out
 
 
-FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime
+FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime
 ENV ASPNETCORE_URLS http://+:8080
 ENV ASPNETCORE_URLS http://+:8080
 WORKDIR /app
 WORKDIR /app
 COPY --from=build /app/out ./
 COPY --from=build /app/out ./

+ 5 - 5
frameworks/FSharp/giraffe/src/App/App.fsproj

@@ -1,15 +1,15 @@
 <Project Sdk="Microsoft.NET.Sdk.Web">
 <Project Sdk="Microsoft.NET.Sdk.Web">
 
 
   <PropertyGroup>
   <PropertyGroup>
-    <TargetFramework>net5.0</TargetFramework>
+    <TargetFramework>net6.0</TargetFramework>
     <EnableDefaultContentItems>false</EnableDefaultContentItems>
     <EnableDefaultContentItems>false</EnableDefaultContentItems>
   </PropertyGroup>
   </PropertyGroup>
 
 
   <ItemGroup>
   <ItemGroup>
-    <PackageReference Update="FSharp.Core" Version="6.0.0" />
-    <PackageReference Include="Dapper" Version="2.0.90" />
-    <PackageReference Include="Giraffe" Version="5.0.0" />
-    <PackageReference Include="Npgsql" Version="5.0.7" />
+    <PackageReference Update="FSharp.Core" Version="6.0.1" />
+    <PackageReference Include="Dapper" Version="2.0.123" />
+    <PackageReference Include="Giraffe" Version="6.0.0-alpha-1" />
+    <PackageReference Include="Npgsql" Version="6.0.0" />
   </ItemGroup>
   </ItemGroup>
 
 
   <ItemGroup>
   <ItemGroup>

+ 24 - 17
frameworks/FSharp/giraffe/src/App/Program.fs

@@ -99,14 +99,16 @@ module HttpHandlers =
             route "/fortunes" fortunes
             route "/fortunes" fortunes
         ]
         ]
 
 
+
 module Main =
 module Main =
     open Microsoft.AspNetCore.Builder
     open Microsoft.AspNetCore.Builder
     open Microsoft.AspNetCore.Hosting
     open Microsoft.AspNetCore.Hosting
     open Microsoft.Extensions.DependencyInjection
     open Microsoft.Extensions.DependencyInjection
     open Giraffe
     open Giraffe
     open Giraffe.EndpointRouting
     open Giraffe.EndpointRouting
+    open Microsoft.Extensions.Hosting    
 
 
-    [<EntryPoint>]
+    [<EntryPoint>]    
     let main args =
     let main args =
         let jsonMode =
         let jsonMode =
             match args with
             match args with
@@ -128,20 +130,25 @@ module Main =
                 NewtonsoftJson.Serializer(NewtonsoftJson.Serializer.DefaultSettings)
                 NewtonsoftJson.Serializer(NewtonsoftJson.Serializer.DefaultSettings)
                 :> Json.ISerializer
                 :> Json.ISerializer
 
 
-        WebHostBuilder()
-            .UseKestrel()
-            .Configure(
-                fun builder ->
-                    builder
-                        .UseRouting()
-                        .UseGiraffe HttpHandlers.endpoints |> ignore)
-            .ConfigureServices(
-                fun services ->
-                    services
-                        .AddRouting()
-                        .AddGiraffe()
-                        .AddSingleton(jsonSerializer)
-                    |> ignore)
-            .Build()
-            .Run()
+        let configureApp (appBuilder : IApplicationBuilder) =
+            appBuilder
+                .UseRouting()
+                .UseGiraffe HttpHandlers.endpoints
+            |> ignore
+
+        let configureServices (services : IServiceCollection) =
+            services
+                .AddRouting()
+                .AddGiraffe()
+                .AddSingleton(jsonSerializer)
+            |> ignore
+
+        let builder = WebApplication.CreateBuilder(args)
+        configureServices builder.Services
+
+        let app = builder.Build()
+
+        configureApp app
+        app.Run()
+
         0
         0