a series about learning aspnetcore using F# interactive
Installing dotnet-sdk π°
brew install dotnet // macwinget install -e --id Microsoft.dotnet //win
To follow along you need a working dotnet environment, so either from command line and vscode, or using the full fledged IDEs Visual Studio or Rider.
If you use VsCode already, also install ionide extensions for F#.
Testing dotnet βοΈ
dotnet fsi
//... starts the interactive promptlet x = "world";; //always add double semicolon to execute!$"hello {x}";;#quit;; //... exit the prompt
Creating an F# script file π
mkdir fscripts && cd fscripts && touch host.fsx && code .
Generic Host π
here #r references nuget packages (~modules) in the script,
with selection plus alt/option + enter we can execute parts of the script in the REPL and evaluate the results!
Service Registration (DI) π¨βπ¬
We can register our services (MyApp or MyBackgroundApp see later..) and configure them with the usual convention of Microsoft.Extensions.DependencyInjection package.. You have different lifetime scopes and different registrations available, you can explore the topic here.
Running our App πββ
We can instantiate our App (IHost), start it , and stop it by selecting and running the specified lines! Amazing π»
Background Job β°
If we want to run something in a loop or timed fashion, we can use Microsoftβs Background service, and implement the ExecuteAsync function in a loop, but other possibilities could be explored here: e.g. use reactive RX extensions to produce scheduled observables in time?
Interactive Results
Enjoy! and see you in the next episode where we will use a WebHost builder!
Have fun learning dotnet with F#!