Learning Aspnet core πŸ‘©β€πŸ«

jkone27
2 min readMar 2, 2022

a series about learning aspnetcore using F# interactive

from microsoft official docs of generic host

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 prompt
let 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#!

--

--