…
|
||
---|---|---|
.. | ||
Grains | ||
HelloWorld | ||
HelloWorldInterfaces | ||
Directory.Build.props | ||
Directory.Build.targets | ||
FSharpHelloWorld.sln | ||
README.md |
README.md
languages | products | page_type | name | urlFragment | description | |||
---|---|---|---|---|---|---|---|---|
|
|
sample | Orleans F# sample app | orleans-fsharp-sample | An example of an Orleans sample app written in F#. |
F# sample app
This sample demonstrates how to use F# to write grain code. The sample consists of three projects:
- HelloWorldInterfaces: a C# project containing a grain interface,
IHelloGrain
. - Grains: an F# projects implementing
IHelloGrain
. - HelloWorld: A C# project to host the grains.
The Microsoft.Orleans.Sdk
package does not support emitting F# code, however, it supports analyzing F# assemblies and emitting C# code. Therefore, this sample works by instructing the code generator to analyze the Grains
project when it is generating code for the HelloWorld
project. This is accomplished using the following directive in HelloWorld
's Program.cs
file:
[assembly: GenerateCodeForDeclaringAssembly(typeof(Grains.HelloGrain))]
With the above attribute in place, the code generator analyzes the F# assembly and emits C# code into the HelloWorld
project.
Sample prerequisites
This sample is written in C# and targets .NET 8.0. It requires the .NET 8.0 SDK or later.
Building the sample
To download and run the sample, follow these steps:
- Download and unzip the sample.
- In Visual Studio (2022 or later):
- On the menu bar, choose File > Open > Project/Solution.
- Navigate to the folder that holds the unzipped sample code, and open the C# project (.csproj) file.
- Choose the F5 key to run with debugging, or Ctrl+F5 keys to run the project without debugging.
- From the command line:
- Navigate to the folder that holds the unzipped sample code.
- At the command line, type
dotnet run
.
Running the sample
Run the sample by opening a terminal window and executing the following at the command prompt:
dotnet run --project HelloWorld