Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace TaskBuilder with Ply #421

Merged
merged 9 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ let webApp =

Another important aspect of Giraffe is that it natively works with .NET's `Task` and `Task<'T>` objects instead of relying on F#'s `async {}` workflows. The main benefit of this is that it removes the necessity of converting back and forth between tasks and async workflows when building a Giraffe web application (because ASP.NET Core only works with tasks out of the box).

For this purpose Giraffe uses the `task {}` computation expression from the [TaskBuilder.fs](https://www.nuget.org/packages/TaskBuilder.fs/) NuGet package. Syntactically it works identical to F#'s async workflows (after opening the `FSharp.Control.Tasks.V2.ContextInsensitive` module):
For this purpose Giraffe uses the `task {}` computation expression from the [Ply](https://www.nuget.org/packages/Ply/) NuGet package. Syntactically it works identical to F#'s async workflows (after opening the `FSharp.Control.Tasks.Builders` module):

```fsharp
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders
open Giraffe

let personHandler =
Expand All @@ -167,14 +167,14 @@ let personHandler =
}
```

The `task {}` CE is an independent project maintained by [Robert Peele](https://github.com/rspeele), for more information please visit the official [TaskBuilder.fs](https://github.com/rspeele/TaskBuilder.fs) GitHub repository.
The `task {}` CE is an independent project maintained by [Crowded](https://github.com/crowded), for more information please visit the official [Ply](https://github.com/crowded/ply) GitHub repository.

**IMPORTANT NOTICE**

If you have `do!` bindings in your Giraffe web application then you must open the `FSharp.Control.Tasks.V2.ContextInsensitive` namespace to resolve any type inference issues:

```fsharp
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders
```

### Ways of creating a new HttpHandler
Expand Down Expand Up @@ -212,7 +212,7 @@ Because an `HttpHandler` is defined as `HttpFunc -> HttpContext -> HttpFuncResul
The most verbose version of defining a new `HttpHandler` function is by explicitly returning a `Task<HttpContext option>`. This is useful when an async operation needs to be called from within an `HttpHandler` function:

```fsharp
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders

type Person = { Name : string }

Expand Down
2 changes: 1 addition & 1 deletion src/Giraffe/Auth.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Auth =
open Microsoft.AspNetCore.Http
open Microsoft.AspNetCore.Authentication
open Microsoft.AspNetCore.Authorization
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders

/// <summary>
/// Challenges a client to authenticate via a specific authScheme.
Expand Down
2 changes: 1 addition & 1 deletion src/Giraffe/Core.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Core =
open System.Globalization
open Microsoft.AspNetCore.Http
open Microsoft.Extensions.Logging
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders
open Giraffe.ViewEngine

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Giraffe/EndpointRouting.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ open Microsoft.AspNetCore.Http
open Microsoft.AspNetCore.Routing
open Microsoft.FSharp.Reflection
open FSharp.Core
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders
open Giraffe

module private RouteTemplateBuilder =
Expand Down
4 changes: 2 additions & 2 deletions src/Giraffe/Giraffe.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@

<ItemGroup>
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="1.3.*" />
<PackageReference Include="System.Text.Json" Version="5.0.*" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.*" />
<PackageReference Include="Utf8Json" Version="1.3.*" />
<PackageReference Include="TaskBuilder.fs" Version="2.1.*" />
<PackageReference Include="System.Text.Json" Version="5.0.*" />
<PackageReference Include="Ply" Version="0.1.*" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.*" PrivateAssets="All" />
<PackageReference Include="Giraffe.ViewEngine" Version="1.3.*" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Giraffe/Helpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Giraffe
module Helpers =
open System
open System.IO
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders

/// <summary>
/// Checks if an object is not null.
Expand Down
2 changes: 1 addition & 1 deletion src/Giraffe/HttpContextExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.Primitives
open Microsoft.Extensions.Logging
open Microsoft.Net.Http.Headers
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders
open Giraffe.ViewEngine

type MissingDependencyException(dependencyName : string) =
Expand Down
2 changes: 1 addition & 1 deletion src/Giraffe/Json.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module NewtonsoftJson =
open System.Text
open System.Threading.Tasks
open Microsoft.IO
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders
open Newtonsoft.Json
open Newtonsoft.Json.Serialization

Expand Down
2 changes: 1 addition & 1 deletion src/Giraffe/Middleware.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ open Microsoft.AspNetCore.Http
open Microsoft.Extensions.Logging
open Microsoft.Extensions.DependencyInjection
open Microsoft.Extensions.DependencyInjection.Extensions
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders

// ---------------------------
// Default middleware
Expand Down
2 changes: 1 addition & 1 deletion src/Giraffe/Preconditional.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ open Microsoft.AspNetCore.Http
open Microsoft.AspNetCore.Http.Headers
open Microsoft.Extensions.Primitives
open Microsoft.Net.Http.Headers
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders

type Precondition =
| NoConditionsSpecified
Expand Down
2 changes: 1 addition & 1 deletion src/Giraffe/Routing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Giraffe
[<RequireQualifiedAccess>]
module SubRouting =
open Microsoft.AspNetCore.Http
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders

[<Literal>]
let private RouteKey = "giraffe_route"
Expand Down
2 changes: 1 addition & 1 deletion src/Giraffe/Streaming.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ open Microsoft.AspNetCore.Http
open Microsoft.AspNetCore.Http.Extensions
open Microsoft.Extensions.Primitives
open Microsoft.Net.Http.Headers
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders

// ---------------------------
// HTTP Range parsing
Expand Down
2 changes: 1 addition & 1 deletion tests/Giraffe.Tests/AuthTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Giraffe.Tests.AuthTests
open System.IO
open System.Security.Claims
open Microsoft.AspNetCore.Http
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders
open NSubstitute
open Xunit
open Giraffe
Expand Down
2 changes: 1 addition & 1 deletion tests/Giraffe.Tests/Helpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ open Microsoft.AspNetCore.Hosting
open Microsoft.AspNetCore.TestHost
open Microsoft.AspNetCore.Builder
open Microsoft.Extensions.DependencyInjection
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders
open Xunit
open NSubstitute
open Utf8Json
Expand Down
2 changes: 1 addition & 1 deletion tests/Giraffe.Tests/HttpContextExtensionsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open System.IO
open System.Threading.Tasks
open Microsoft.AspNetCore.Http
open Microsoft.Extensions.Primitives
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders
open Xunit
open NSubstitute
open Giraffe
Expand Down
2 changes: 1 addition & 1 deletion tests/Giraffe.Tests/HttpHandlerTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open System.IO
open System.Collections.Generic
open Microsoft.AspNetCore.Http
open Microsoft.Extensions.Primitives
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders
open Xunit
open NSubstitute
open Giraffe
Expand Down
2 changes: 1 addition & 1 deletion tests/Giraffe.Tests/ModelBindingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ open System.Text
open System.Threading.Tasks
open Microsoft.AspNetCore.Http
open Microsoft.Extensions.Primitives
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders
open Xunit
open NSubstitute
open Giraffe
Expand Down
2 changes: 1 addition & 1 deletion tests/Giraffe.Tests/ModelValidationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open System.Net.Http
open Microsoft.AspNetCore.Builder
open Microsoft.Extensions.DependencyInjection
open Microsoft.Extensions.Logging
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders
open Xunit
open Giraffe

Expand Down
2 changes: 1 addition & 1 deletion tests/Giraffe.Tests/PreconditionalTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ open Microsoft.AspNetCore.Http
open Microsoft.AspNetCore.Builder
open Microsoft.Extensions.DependencyInjection
open Microsoft.Extensions.Logging
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders
open Xunit
open Giraffe

Expand Down
2 changes: 1 addition & 1 deletion tests/Giraffe.Tests/RoutingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ open System
open System.IO
open System.Collections.Generic
open Microsoft.AspNetCore.Http
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders
open Xunit
open NSubstitute
open Giraffe
Expand Down
2 changes: 1 addition & 1 deletion tests/Giraffe.Tests/StreamingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open System.Net.Http
open Microsoft.AspNetCore.Builder
open Microsoft.Extensions.DependencyInjection
open Microsoft.Extensions.Logging
open FSharp.Control.Tasks.V2.ContextInsensitive
open FSharp.Control.Tasks.Builders
open Xunit
open Giraffe

Expand Down