Browse Source

[F#] Update to F# 6.0 (#6870)

* [F#] Update to F# 6.0

* Minor cleanup of Frank App
Ryan Riley 3 years ago
parent
commit
0321b58504

+ 1 - 1
frameworks/FSharp/falco/README.md

@@ -5,7 +5,7 @@ This includes tests for plaintext, json, and fortunes HTML serialization.
 
 **Language**
 
-* F# 4.7
+* F# 6.0
 
 **Platforms**
 

+ 1 - 1
frameworks/FSharp/falco/src/App/App.fsproj

@@ -16,7 +16,7 @@
   </ItemGroup>
 
   <ItemGroup>
-    <PackageReference Update="FSharp.Core" Version="5.0.2" />
+    <PackageReference Update="FSharp.Core" Version="6.0.0" />
     <PackageReference Include="Donald" Version="3.0.*" />
     <PackageReference Include="Falco" Version="2.0.*" />    
     <PackageReference Include="Npgsql" Version="5.0.7" />

+ 2 - 6
frameworks/FSharp/falco/src/App/Fortune.fs

@@ -1,9 +1,9 @@
 module App.Fortune    
 
 open System.Data
+open System.Threading.Tasks     
 open Donald
 open Falco
-open FSharp.Control.Tasks
  
 type FortuneModel = 
    {
@@ -19,8 +19,6 @@ module FortuneModel =
        }
 
 module Service = 
-    open System.Threading.Tasks     
-        
     module ListQuery =              
         type LoadFortunes = unit -> Task<FortuneModel list>
 
@@ -44,8 +42,6 @@ module Service =
 
 
 module Db =    
-    open System.Threading.Tasks    
-    
     let selectAsync (connection : IDbConnection) : Task<FortuneModel list> =        
         queryAsync 
             "SELECT id, message FROM fortune"
@@ -84,4 +80,4 @@ let handleIndex : HttpHandler =
                 |> (fortunes 
                     |> View.index 
                     |> Response.ofHtml)                    
-        }
+        } :> Task

+ 1 - 1
frameworks/FSharp/frank/README.md

@@ -5,7 +5,7 @@ This includes tests for plaintext, json, and fortunes HTML serialization.
 
 **Language**
 
-* F# 4.7
+* F# 6.0
 
 **Platforms**
 

+ 2 - 2
frameworks/FSharp/frank/src/App/App.fsproj

@@ -11,11 +11,11 @@
   <ItemGroup>
     <PackageReference Include="Dapper" Version="2.0.90" />
     <PackageReference Include="Frank" Version="6.2.0" />
-    <PackageReference Include="FSharp.Data.JsonSchema" Version="0.1.0" />
+    <PackageReference Include="FSharp.Data.JsonSchema" Version="1.0.0" />
     <PackageReference Include="Giraffe" Version="5.0.0" />
     <PackageReference Include="Giraffe.ViewEngine" Version="1.4.0" />
     <PackageReference Include="Npgsql" Version="5.0.7" />
-    <PackageReference Update="FSharp.Core" Version="5.0.2" />
+    <PackageReference Update="FSharp.Core" Version="6.0.0" />
   </ItemGroup>
 
   <ItemGroup>

+ 16 - 12
frameworks/FSharp/frank/src/App/Program.fs

@@ -1,26 +1,27 @@
 module App.App
 
 open System
-open System.IO
 open System.Text
 open System.Text.Json.Serialization
 open System.Text.Json
 open System.Threading.Tasks
 open Microsoft.AspNetCore.Hosting
 open Microsoft.AspNetCore.Http
+open Microsoft.Extensions.DependencyInjection
 open Microsoft.Extensions.Logging
 open Dapper
 open Giraffe
+open Giraffe.ViewEngine
 open Frank.Builder
-open FSharp.Control.Tasks
 open Npgsql
 open Models
 
 let inline contentLength x = new Nullable<int64> ( int64 x )
 
+let options = JsonSerializerOptions()
+options.Converters.Add(JsonFSharpConverter())
+
 let json' : HttpContext -> Task =
-    let options = JsonSerializerOptions()
-    options.Converters.Add(JsonFSharpConverter())
     fun ctx ->
         ctx.Response.ContentType <- "application/json"
         ctx.Response.StatusCode <- 200
@@ -36,21 +37,23 @@ let text' (msg:string): HttpContext -> Task =
         ctx.Response.Body.WriteAsync(bytes, 0, bytes.Length)
 
 // Pulled from Giraffe example
-let fortunes' = 
-    let extra = { id = 0; message = "Additional fortune added at request time." }
-    fun next (ctx: HttpContext) ->
-        let conn = new NpgsqlConnection(ConnectionString)
-        ctx.Response.RegisterForDispose conn
+let extra = { id = 0; message = "Additional fortune added at request time." }
+let fortunes' : HttpHandler = 
+    fun _ ctx ->
         task {
+            use conn = new NpgsqlConnection(ConnectionString)
             let! data = conn.QueryAsync<Fortune>("SELECT id, message FROM fortune")
 
-            let fortunes = 
+            let view =
                 let xs = data.AsList()
                 xs.Add extra
                 xs.Sort FortuneComparer
-                xs
+                HtmlViews.fortunes xs
+
+            let bytes = RenderView.AsBytes.htmlDocument view
 
-            return! htmlView (HtmlViews.fortunes fortunes) next ctx
+            ctx.SetContentType "text/html;charset=utf-8"
+            return! ctx.WriteBytesAsync bytes
         }
 
 // Resources
@@ -79,6 +82,7 @@ let fortunes =
 let main args = 
     webHost args {
         useDefaults
+        service (fun services -> services.AddSingleton(options))
         configure (fun bldr ->
             bldr.ConfigureLogging(fun c -> c.ClearProviders() |> ignore)
                 .UseKestrel())

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

@@ -10,7 +10,7 @@ This application tests Giraffe in 3 modes:
 
 **Language**
 
-* F# 5.0
+* F# 6.0
 
 **Platforms**
 

+ 1 - 0
frameworks/FSharp/giraffe/src/App/App.fsproj

@@ -6,6 +6,7 @@
   </PropertyGroup>
 
   <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" />

+ 0 - 1
frameworks/FSharp/giraffe/src/App/Program.fs

@@ -65,7 +65,6 @@ module HttpHandlers =
     open Giraffe
     open Giraffe.EndpointRouting
     open Giraffe.ViewEngine
-    open FSharp.Control.Tasks
     open Dapper
     open Npgsql
 

+ 1 - 1
frameworks/FSharp/suave/src/App/App.fsproj

@@ -12,7 +12,7 @@
 
   <ItemGroup>
     <PackageReference Include="Suave" Version="2.6.1" />
-    <PackageReference Update="FSharp.Core" Version="5.0.2" />
+    <PackageReference Update="FSharp.Core" Version="6.0.0" />
   </ItemGroup>
 
 </Project>

+ 1 - 1
frameworks/FSharp/zebra/README.md

@@ -7,7 +7,7 @@ Zebra is a new F# functional Asp.net Framework Wrapper that utalises a shared st
 
 **Language**
 
-* F# 4.6
+* F# 6.0
 
 **Platforms**
 

+ 1 - 1
frameworks/FSharp/zebra/src/App/App.fsproj

@@ -12,7 +12,7 @@
     <PackageReference Include="Dapper" Version="2.0.90" />
     <PackageReference Include="Npgsql" Version="5.0.7" />
     <PackageReference Include="Utf8Json" Version="1.3.7" />
-    <PackageReference Update="FSharp.Core" Version="5.0.2" />
+    <PackageReference Update="FSharp.Core" Version="6.0.0" />
   </ItemGroup>
 
   <ItemGroup>