Header menu logo FSharp.AspNetCore.WebAppBuilder

WebAppBuilder Type

Creates a web application using computation expression syntax.

See also: Gets, Posts, Puts, Deletes, Patches.

Instance members

Instance member Description

build ()

Full Usage: build ()

Parameters:
    () : unit

Returns: WebApplication

Calls WebApplicationBuilder.Build on the web application builder, returning a WebApplication.

() : unit
Returns: WebApplication

buildWith configureBuilder

Full Usage: buildWith configureBuilder

Parameters:
Returns: WebApplication

Applies the given function to the web application builder immediately before calling WebApplicationBuilder.Build on it, returning a WebApplication. Any following operations must operate on the built WebApplication, not the WebApplicationBuilder.

configureBuilder : WebApplicationBuilder -> 'a

The function to apply to the web application builder.

Returns: WebApplication
Example

Use this operation to enable easy integration testing.

In your Program.fs:

 let app configureBuilder =
     webApp {
         buildWith configureBuilder
         get "/hello" (fun () -> "🌎")
     }

 (app ignore).Run ()
val app: configureBuilder: 'a -> 'b
val configureBuilder: 'a
val ignore: value: 'T -> unit
In your test file:
 [<Fact>]
 let ``Hello, world`` () =
     task {
         use app = Program.app (fun builder -> builder.WebHost.UseTestServer ())
         do! app.StartAsync ()
         use client = app.GetTestClient ()
         let! response = client.GetStringAsync "hello"
         Assert.Equal ("🌎", response)
     }
     |> Async.AwaitTask
     |> Async.RunSynchronously
val task: TaskBuilder
val app: System.IAsyncDisposable
val client: System.IAsyncDisposable
val response: obj
Multiple items
type Async = static member AsBeginEnd: computation: ('Arg -> Async<'T>) -> ('Arg * AsyncCallback * obj -> IAsyncResult) * (IAsyncResult -> 'T) * (IAsyncResult -> unit) static member AwaitEvent: event: IEvent<'Del,'T> * ?cancelAction: (unit -> unit) -> Async<'T> (requires delegate and 'Del :> Delegate) static member AwaitIAsyncResult: iar: IAsyncResult * ?millisecondsTimeout: int -> Async<bool> static member AwaitTask: task: Task<'T> -> Async<'T> + 1 overload static member AwaitWaitHandle: waitHandle: WaitHandle * ?millisecondsTimeout: int -> Async<bool> static member CancelDefaultToken: unit -> unit static member Catch: computation: Async<'T> -> Async<Choice<'T,exn>> static member Choice: computations: Async<'T option> seq -> Async<'T option> static member FromBeginEnd: beginAction: (AsyncCallback * obj -> IAsyncResult) * endAction: (IAsyncResult -> 'T) * ?cancelAction: (unit -> unit) -> Async<'T> + 3 overloads static member FromContinuations: callback: (('T -> unit) * (exn -> unit) * (OperationCanceledException -> unit) -> unit) -> Async<'T> ...

--------------------
type Async<'T>
static member Async.AwaitTask: task: System.Threading.Tasks.Task -> Async<unit>
static member Async.AwaitTask: task: System.Threading.Tasks.Task<'T> -> Async<'T>
static member Async.RunSynchronously: computation: Async<'T> * ?timeout: int * ?cancellationToken: System.Threading.CancellationToken -> 'T

builder configureBuilder

Full Usage: builder configureBuilder

Parameters:
Returns: WebApplicationBuilder

Applies the given function to the WebApplicationBuilder being used to build the app. Useful when multiple properties of the builder need to be accessed at once.

configureBuilder : WebApplicationBuilder -> 'a

The function to apply to the web application builder.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         builder (fun builder ->
             builder.Services.AddSingleton
                 (EnvironmentName builder.Environment.EnvironmentName))
     }
val app: obj

configuration configureConfiguration

Full Usage: configuration configureConfiguration

Parameters:
    configureConfiguration : ConfigurationManager -> 'a - The function to apply to the app configuration.

Returns: WebApplicationBuilder

Applies the given function to the WebApplicationBuilder.Configuration property of the WebApplicationBuilder being used to build the app.

configureConfiguration : ConfigurationManager -> 'a

The function to apply to the app configuration.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         configuration (fun config -> config.AddIniFile "config.ini")
     }
val app: obj

configurationValue key ctor

Full Usage: configurationValue key ctor

Parameters:
    key : string - The key to look up in the app configuration.
    ctor : 'Value -> 'ConfiguredValue - The constructor to pass the configuration value into.

Returns: WebApplicationBuilder

Adds a strongly-typed configuration value to the app's service collection.

key : string

The key to look up in the app configuration.

ctor : 'Value -> 'ConfiguredValue

The constructor to pass the configuration value into.

Returns: WebApplicationBuilder
InvalidOperationException Raised when no value with the given key is found in the app's configuration.
Example

 {
   "AppSettings": {
     "SqlCommandTimeout": "00:05:00"
   }
 }
 type SqlCommandTimeout = SqlCommandTimeout of TimeSpan

 let app =
     webApp {
         configurationValue "AppSettings:SqlCommandTimeout" SqlCommandTimeout
     }
Multiple items
union case SqlCommandTimeout.SqlCommandTimeout: obj -> SqlCommandTimeout

--------------------
type SqlCommandTimeout = | SqlCommandTimeout of obj
type SqlCommandTimeout = | SqlCommandTimeout of obj
val app: obj

configure configureOptions

Full Usage: configure configureOptions

Parameters:
    configureOptions : 'TOptions -> 'a - The action to apply to the options.

Returns: WebApplicationBuilder

Applies the given configureOptions action to the registered options of the specified type.

configureOptions : 'TOptions -> 'a

The action to apply to the options.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         configure (fun (jsonOptions : JsonOptions) ->
             jsonOptions.SerializerOptions.Converters.Add (JsonStringEnumConverter ()))
     }
val app: obj

connectionString name ctor

Full Usage: connectionString name ctor

Parameters:
    name : string - The name of the connection string to look up in the ConnectionStrings section of the app configuration.
    ctor : string -> 'ConnectionString - The constructor to pass the configuration value into.

Returns: WebApplicationBuilder

Adds a strongly-typed connection string to the app's service collection. Performs a lookup in the app's configuration at the path "ConnectionStrings:<name>".

name : string

The name of the connection string to look up in the ConnectionStrings section of the app configuration.

ctor : string -> 'ConnectionString

The constructor to pass the configuration value into.

Returns: WebApplicationBuilder
InvalidOperationException Raised when no connection string with the given name is found in the app's configuration.
Example

 {
   "ConnectionStrings": {
     "SqlDb": "Data Source=localhost\\LocalDb;Initial Catalog=MyDb;IntegratedSecurity=true"
   }
 }
 type SqlDbConnectionString = SqlDbConnectionString of string

 let app =
     webApp {
         connectionString "SqlDb" SqlDbConnectionString
     }
Multiple items
union case SqlDbConnectionString.SqlDbConnectionString: string -> SqlDbConnectionString

--------------------
type SqlDbConnectionString = | SqlDbConnectionString of string
type SqlDbConnectionString = | SqlDbConnectionString of string
Multiple items
val string: value: 'T -> string

--------------------
type string = System.String
val app: obj

environmentVariables

Full Usage: environmentVariables

Returns: WebApplicationBuilder

Adds the ability to read configuration from environment variables.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         environmentVariables
     }
val app: obj

fromConfig configure

Full Usage: fromConfig configure

Parameters:
Returns: WebApplicationBuilder

Adds a singleton service produced by applying the given configure function to the WebApplicationBuilder's WebApplicationBuilder.Configuration property.

configure : IConfiguration -> 'ConfiguredValue
Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         fromConfig (fun config -> Service config["MyKey"])
     }
val app: obj

host configureHost

Full Usage: host configureHost

Parameters:
Returns: WebApplicationBuilder

Applies the given action to the WebApplicationBuilder.Host property of the WebApplicationBuilder being used to build the app.

configureHost : ConfigureHostBuilder -> 'a

The function to apply to the host builder.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         host (fun host ->
             host.ConfigureHostOptions (fun options ->
                 options.BackgroundServiceExceptionBehavior <-
                     BackgroundServiceExceptionBehavior.StopHost))
     }
val app: obj

hostedService implementationFactory

Full Usage: hostedService implementationFactory

Parameters:
Returns: WebApplicationBuilder

Adds a hosted service to the app's service collection.

implementationFactory : IServiceProvider -> 'a
Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         hostedService (fun serviceProvider ->
             MyHostedService (serviceProvider.GetRequireService<OtherService> ()))
     }
val app: obj

hostedService serviceType

Full Usage: hostedService serviceType

Parameters:
    serviceType : Type

Returns: WebApplicationBuilder

Adds a hosted service to the app's service collection.

serviceType : Type
Returns: WebApplicationBuilder
InvalidOperationException Raised if serviceType does not implement IHostedService.
Example

 let app =
     webApp {
         hostedService typeof<MyHostedService>
     }
val app: obj
val typeof<'T> : System.Type

jsonFile path

Full Usage: jsonFile path

Parameters:
    path : string - The path of the JSON configuration file.

Returns: WebApplicationBuilder

Adds a required JSON configuration file to the WebApplicationBuilder's WebApplicationBuilder.Configuration.

path : string

The path of the JSON configuration file.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         jsonFile "auth.json"
     }
val app: obj

logging configureLogging

Full Usage: logging configureLogging

Parameters:
    configureLogging : ILoggingBuilder -> 'a - The function to apply to the logging builder.

Returns: WebApplicationBuilder

Applies the given action to the WebApplicationBuilder.Logging property of the WebApplicationBuilder being used to build the app.

configureLogging : ILoggingBuilder -> 'a

The function to apply to the logging builder.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         logging (fun logging ->
             logging.ClearProviders ()
             logging.AddConsole ())
     }
val app: obj

optionalJsonFile path

Full Usage: optionalJsonFile path

Parameters:
    path : string - The path of the JSON configuration file.

Returns: WebApplicationBuilder

Adds an optional JSON configuration file to the WebApplicationBuilder's WebApplicationBuilder.Configuration.

path : string

The path of the JSON configuration file.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         optionalJsonFile "auth.json"
     }
val app: obj

scoped serviceType implementationFactory

Full Usage: scoped serviceType implementationFactory

Parameters:
    serviceType : Type - The type of the service to add.
    implementationFactory : IServiceProvider -> 'TImplementation - A function that produces the service implementation.

Returns: WebApplicationBuilder

Adds a scoped service of the type specified in serviceType using an implementation provided by applying the given implementationFactory to the app's service provider.

serviceType : Type

The type of the service to add.

implementationFactory : IServiceProvider -> 'TImplementation

A function that produces the service implementation.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         scoped
             typeof<IService>
             (fun serviceProvider -> Service (serviceProvider.GetRequiredService<OtherService> ()))
     }
val app: obj
val typeof<'T> : System.Type

scoped serviceType implementationType

Full Usage: scoped serviceType implementationType

Parameters:
    serviceType : Type - The type of the service to add.
    implementationType : Type - The type of the service implementation to add.

Returns: WebApplicationBuilder

Adds a scoped service of the type specified in serviceType with an implementation of the type specified in implementationType to the app's service collection.

serviceType : Type

The type of the service to add.

implementationType : Type

The type of the service implementation to add.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         scoped typeof<IService> typeof<Service>
     }
val app: obj
val typeof<'T> : System.Type

scoped serviceType

Full Usage: scoped serviceType

Parameters:
    serviceType : Type - The type of the service to add.

Returns: WebApplicationBuilder

Adds a scoped service of the type specified in serviceType to the app's service collection.

serviceType : Type

The type of the service to add.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         scoped typeof<Service>
     }
val app: obj
val typeof<'T> : System.Type

services configureServices

Full Usage: services configureServices

Parameters:
Returns: WebApplicationBuilder

Applies the given action to the WebApplicationBuilder.Services and WebApplicationBuilder.Configuration properties of the WebApplicationBuilder being used to build the app.

See also: Priority1.Services

configureServices : IServiceCollection -> ConfigurationManager -> 'a

The function to apply to the web application builder's service collection.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         services (fun services config ->
             services.Configure<MyOptions> ("MyOptionsName", config.GetSection "MyOptionsSection")
             services.AddEndpointsApiExplorer ()
             services.AddSwaggerGen ()
             services.AddControllers ())
     }
val app: obj

singleton implementationInstance

Full Usage: singleton implementationInstance

Parameters:
    implementationInstance : 'TService - An object to use as the service implementation.

Returns: WebApplicationBuilder

Adds a singleton service using the given implementationInstance.

implementationInstance : 'TService

An object to use as the service implementation.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         singleton (Service ())
     }
val app: obj

singleton serviceType implementationInstance

Full Usage: singleton serviceType implementationInstance

Parameters:
    serviceType : Type - The type of the service to add.
    implementationInstance : obj - An object to use as the service implementation.

Returns: WebApplicationBuilder

Adds a singleton service of the type specified in serviceType using the given implementationInstance.

serviceType : Type

The type of the service to add.

implementationInstance : obj

An object to use as the service implementation.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         singleton typeof<IService> (Service ())
     }
val app: obj
val typeof<'T> : System.Type

singleton serviceType implementationFactory

Full Usage: singleton serviceType implementationFactory

Parameters:
    serviceType : Type - The type of the service to add.
    implementationFactory : IServiceProvider -> 'TImplementation - A function that produces the service implementation.

Returns: WebApplicationBuilder

Adds a singleton service of the type specified in serviceType using an implementation provided by applying the given implementationFactory to the app's service provider.

serviceType : Type

The type of the service to add.

implementationFactory : IServiceProvider -> 'TImplementation

A function that produces the service implementation.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         singleton
             typeof<IService>
             (fun serviceProvider -> Service (serviceProvider.GetRequiredService<OtherService> ()))
     }
val app: obj
val typeof<'T> : System.Type

singleton serviceType implementationType

Full Usage: singleton serviceType implementationType

Parameters:
    serviceType : Type - The type of the service to add.
    implementationType : Type - The type of the service implementation to add.

Returns: WebApplicationBuilder

Adds a singleton service of the type specified in serviceType with an implementation of the type specified in implementationType to the app's service collection.

serviceType : Type

The type of the service to add.

implementationType : Type

The type of the service implementation to add.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         singleton typeof<IService> typeof<Service>
     }
val app: obj
val typeof<'T> : System.Type

singleton serviceType

Full Usage: singleton serviceType

Parameters:
    serviceType : Type - The type of the service to add.

Returns: WebApplicationBuilder

Adds a singleton service of the type specified in serviceType to the app's service collection.

serviceType : Type

The type of the service to add.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         singleton typeof<Service>
     }
val app: obj
val typeof<'T> : System.Type

transient serviceType implementationFactory

Full Usage: transient serviceType implementationFactory

Parameters:
    serviceType : Type - The type of the service to add.
    implementationFactory : IServiceProvider -> 'TImplementation - A function that produces the service implementation.

Returns: WebApplicationBuilder

Adds a transient service of the type specified in serviceType using an implementation provided by applying the given implementationFactory to the app's service provider.

serviceType : Type

The type of the service to add.

implementationFactory : IServiceProvider -> 'TImplementation

A function that produces the service implementation.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         transient
             typeof<IService>
             (fun serviceProvider -> Service (serviceProvider.GetRequiredService<OtherService> ()))
     }
val app: obj
val typeof<'T> : System.Type

transient serviceType implementationType

Full Usage: transient serviceType implementationType

Parameters:
    serviceType : Type - The type of the service to add.
    implementationType : Type - The type of the service implementation to add.

Returns: WebApplicationBuilder

Adds a transient service of the type specified in serviceType with an implementation of the type specified in implementationType to the app's service collection.

serviceType : Type

The type of the service to add.

implementationType : Type

The type of the service implementation to add.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         transient typeof<IService> typeof<Service>
     }
val app: obj
val typeof<'T> : System.Type

transient serviceType

Full Usage: transient serviceType

Parameters:
    serviceType : Type - The type of the service to add.

Returns: WebApplicationBuilder

Adds a transient service of the type specified in serviceType to the app's service collection.

serviceType : Type

The type of the service to add.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         transient typeof<Service>
     }
val app: obj
val typeof<'T> : System.Type

webApp configureApp

Full Usage: webApp configureApp

Parameters:
    configureApp : WebApplication -> 'a - The function to apply to the built web application.

Returns: WebApplication

Calls WebApplicationBuilder.Build and applies the given action to the resulting WebApplication.

configureApp : WebApplication -> 'a

The function to apply to the built web application.

Returns: WebApplication
Example

 let app =
     webApp {
         webApp (fun app ->
             app.UseSwagger ()
             app.UseSwaggerUI ()
             app.MapControllers ())
     }
val app: obj

webApp configureApp

Full Usage: webApp configureApp

Parameters:
    configureApp : WebApplication -> 'a - The function to apply to the built web application.

Returns: WebApplication

Applies the given action to the built WebApplication.

configureApp : WebApplication -> 'a

The function to apply to the built web application.

Returns: WebApplication
Example

 let app =
     webApp {
         get "/hello" (fun () -> "🌎")
         webApp (fun app ->
             app.UseSwagger ()
             app.UseSwaggerUI ()
             app.MapControllers ())
     }
val app: obj

webHost configureWebHost

Full Usage: webHost configureWebHost

Parameters:
Returns: WebApplicationBuilder

Applies the given action to the WebApplicationBuilder.WebHost property of the WebApplicationBuilder being used to build the app.

configureWebHost : ConfigureWebHostBuilder -> 'a

The function to apply to the web host builder.

Returns: WebApplicationBuilder
Example

 let app =
     webApp {
         webHost (fun webHost ->
             webHost.ConfigureAppConfiguration (fun context _configBuilder ->
                 context.HostingEnvironment.ApplicationName <- "MyApp"))
     }
val app: obj

Type something to start searching.