Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit 2a2b3a0

Browse files
Updated step 1 and part of step 2 docs
1 parent 26baf95 commit 2a2b3a0

15 files changed

Lines changed: 87 additions & 146 deletions

File tree

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# objects () |> functions
22

3-
_**NOTE:** Once tooling has finalized around .NET Standard 2, I will be bringing the currently done steps up to
4-
current, then continue._
5-
63
## What
74

85
This repository will track the development of a rudimentary multi-site blog platform, in parallel, in 4 different

dox/content/step1/dos.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
### Dos - Step 1
22

3-
For this project, we'll also start with `project.json`, bringing in the dependencies we'll need.
3+
For this project, we'll make sure our project file is `Dos.csproj`, and modify it the way we did [for Uno](./uno.html); we'll include one extra dependency to bring in Nancy.
44

55
[lang=text]
6-
"dependencies": {
7-
"Microsoft.AspNetCore.Owin": "1.0.0",
8-
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
9-
"Nancy": "2.0.0-barneyrubble"
10-
},
6+
<PropertyGroup>
7+
<AssemblyName>Dos</AssemblyName>
8+
<VersionPrefix>1.0.0</VersionPrefix>
9+
<OutputType>Exe</OutputType>
10+
<TargetFramework>netcoreapp2.0</TargetFramework>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Microsoft.AspNetCore.Owin" Version="2.*" />
15+
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.*" />
16+
<PackageReference Include="Nancy" Version="2.0.0-*" IncludePrerelease="true" />
17+
</ItemGroup>
1118

1219
Nancy strives to provide a Super-Duper-Happy-Path (SDHP), where all you have to do is follow their conventions, and everything will "just work." (You can also configure every aspect of it; it's only opinionated in its defaults.) One of these conventions is that the controllers inherit from `NancyModule`, and when they do, no further configuration is required. So, we create the `Modules` directory, and add `HomeModule.cs`, which looks like this:
1320

dox/content/step1/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
For "Hello World" in each environment, we'll create an empty .NET Core console application. To view the entire
44
completed source from this step, see
5-
[the checkpoint for step 1](https://github.com/danieljsummers/FromObjectsToFunctions/tree/step-1).
5+
[the checkpoint for step 1](https://github.com/danieljsummers/FromObjectsToFunctions/tree/step-1-core2).
66

77
All projects were created using `dotnet new -t console -l C#` (or `F#`).
88

dox/content/step1/quatro.fsx

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,26 @@
1212
(**
1313
### Quatro - Step 1
1414
15-
Having [already made the leap to F#](tres.html), we will now do our Hello World in Freya. This is adapted from the
16-
"Getting Started" article on their site.
17-
18-
First up, we'll attack `project.json`. This one will require more modifications\* than the others. Let's start
19-
with the dependencies section:
15+
Having [already made the leap to F#](./tres.html), we will now do our Hello World in Freya. Thanks to the hard work of
16+
Microsoft on .NET Core 2, this process exactly mirrors what we did with Tres, just with a Freya dependency instead of
17+
one for Nancy:
2018
2119
[lang=text]
22-
"dependencies": {
23-
"Freya": "3.0.0-rc01",
24-
"Microsoft.AspNetCore.Owin": "1.0.0",
25-
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
26-
"Microsoft.NETCore.Portable.Compatibility": "1.0.1"
27-
},
28-
29-
Freya should be self-explanatory, and we've seen the Owin and Kestrel imports before. The new one is the last one, and
30-
this package provides fill-ins for some types that used to be defined in `mscorlib` (the big library-to-rule-them-all
31-
that went away between the full .NET framework and .NET Core).
20+
<ItemGroup>
21+
<PackageReference Include="Freya" Version="4.0.0-alpha-*" IncludePrerelease="true" />
22+
<PackageReference Include="Microsoft.AspNetCore.Owin" Version="2.*" />
23+
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.*" />
24+
</ItemGroup>
3225
33-
The frameworks sections needs some attention as well:
26+
We'll go ahead and rename `Program.fs` to `App.fs` to remain consistent among the projects, and tell the compiler about
27+
it:
3428
3529
[lang=text]
36-
"frameworks": {
37-
"netcoreapp1.0": {
38-
"dependencies": {
39-
"Microsoft.NETCore.App": {
40-
"type": "platform",
41-
"version": "1.0.1"
42-
},
43-
"Microsoft.FSharp.Core.netcore": "1.0.0-alpha-160831"
44-
},
45-
"imports": [
46-
"portable-net45+win8+dnxcore50",
47-
"portable-net45+win8",
48-
"net452",
49-
"dnxcore50"
50-
]
51-
}
52-
},
30+
<ItemGroup>
31+
<Compile Include="App.fs" />
32+
</ItemGroup>
5333
54-
These imports allow us to use some Freya dependencies that target Portable Class Libraries (PCLs) that are supported by
55-
.NET Core. Finally, while we're there, change "Program.fs" to "App.fs" in the compiled file list, as we'll rename
56-
`Program.fs` to `App.fs` to remain consistent among the projects.
57-
58-
Now, for `App.fs`:
34+
Now, let's actually write `App.fs`:
5935
*)
6036
namespace Quatro
6137

@@ -112,10 +88,4 @@ has become; the only place we had to `ignore` anything was the "seam" where we i
11288
`dotnet run` should succeed at this point, and localhost:5000 should display our Hello World message.
11389
11490
[Back to Step 1](../step1)
115-
116-
---
117-
118-
\* - Huge props go to @neoeinstein for documenting these settings in
119-
[this Gist](https://gist.github.com/neoeinstein/66c2c8ace158b3e701e206e172e91f8b). I had not seen the PCL compat
120-
package _or_ an import for "net452" in .NET Core before this.
12191
*)

dox/content/step1/tres.fsx

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
(**
1010
### Tres - Step 1
1111
12-
Here, we're making the leap to F#. The changes to `project.json` for the dependent packages are the same as they were
13-
for [Dos](dos.html). F# projects are historically not split into directories, as compilation order is significant, and
14-
having them in the same directory allows the tooling to ensure that the compilation order is preserved. With the
15-
structure of `project.json`, this is not necessarily a limitation (though the tooling still doesn't support it, as of
16-
this writing), but we'll follow it for our purposes here.
12+
Here, we're making the leap to F#. Once we ensure that our project file is named `Tres.fsproj`, the contents of the
13+
file should be the same as they were for [Dos](./dos.html). F# projects are historically not split into directories, as
14+
compilation order is significant, and having them in the same directory allows the tooling to ensure that the
15+
compilation order is preserved. With the structure of the `.fsproj` file, this is not necessarily a limitation (though
16+
the tooling still doesn't support it, as of this writing), but we'll follow it for our purposes here.
1717
1818
The module is created as `HomeModule.fs` in the project root:
1919
*)
@@ -27,7 +27,7 @@ type HomeModule() as this =
2727
do
2828
this.Get("/", fun _ -> "Hello World from Nancy F#")
2929
(**
30-
If you look at [Dos](dos.html), you can see how the translation occurred:
30+
If you look at [Dos](./dos.html), you can see how the translation occurred:
3131
3232
- "using" becomes "open"
3333
- F# does not express constructors in the way C# folks are used to seeing them. Parameters to the class are specified
@@ -72,25 +72,14 @@ look like). An F# source file must start with either a namespace or module decl
7272
name will be `Tres.Startup`, so we have to define a module for our `let` binding / entry point.
7373
7474
At this point, `dotnet build` will fail. I mentioned compilation order earlier; we've added one file and renamed the
75-
other, but we have yet to tell the compiler about them, or how they should be ordered. Back in `project.json`, look for
76-
the `buildOptions` entry, and replace
75+
other, but we have yet to tell the compiler about them, or how they should be ordered. Back in `Tres.fsproj`, between
76+
the `PropertyGroup` and the `ItemGroup`, add the following `ItemGroup`:
7777
7878
[lang=text]
79-
"compile": {
80-
"includeFiles": [
81-
"Program.fs"
82-
]
83-
}
84-
85-
with
86-
87-
[lang=text]
88-
"compile": {
89-
"includeFiles": [
90-
"HomeModule.fs",
91-
"App.fs"
92-
]
93-
}
79+
<ItemGroup>
80+
<Compile Include="HomeModule.fs" />
81+
<Compile Include="App.fs" />
82+
</ItemGroup>
9483
9584
(In the future, we'll add updating this list to our discipline of creating a new file.)
9685

dox/content/step1/uno.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@ will not be using Entity Framework for anything, and though this application wil
55
ASP.NET Core MVC, we will not be using its membership features. Since all of that is out of scope for this effort, and
66
all of this is in the "web" template, we won't use it._ 😃
77

8-
To start, we'll open `project.json` and add the dependencies we'll need:
8+
To start, we'll make sure the `.csproj` file is named `Uno.csproj`. Then, under the first `PropertyGroup` item, we'll add a few items; when we're done, it should look like this:
99

1010
[lang=text]
11-
"dependencies": {
12-
"Microsoft.AspNetCore.Owin": "1.0.0",
13-
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0"
14-
},
11+
<PropertyGroup>
12+
<AssemblyName>Uno</AssemblyName>
13+
<VersionPrefix>1.0.0</VersionPrefix>
14+
<OutputType>Exe</OutputType>
15+
<TargetFramework>netcoreapp2.0</TargetFramework>
16+
</PropertyGroup>
17+
18+
Then, we'll add a new section, `ItemGroup`, and two dependencies:
19+
20+
[lang=text]
21+
<ItemGroup>
22+
<PackageReference Include="Microsoft.AspNetCore.Owin" Version="2.*" />
23+
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.*" />
24+
</ItemGroup>
1525

1626
`dotnet restore` fixes up the actual packages. Next, we'll create the `Startup.cs` file. Within its `Configure` method, we'll do a very basic lambda to return a string:
1727

dox/content/step2/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
### Data Model
22

3-
_(Feel free to browse [the checkpoint for step 2](https://github.com/danieljsummers/FromObjectsToFunctions/tree/step-2)
4-
as you follow along.)_
3+
_(Feel free to browse
4+
[the checkpoint for step 2](https://github.com/danieljsummers/FromObjectsToFunctions/tree/step-2-core2) as you follow
5+
along.)_
56

67
#### Overview
78

dox/content/step2/quatro.fsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ are their own type. Also, each condition does not have to have the same type; i
3636
one condition that has one type (or no type at all), and other condition with a completely different type. (We don't
3737
use that with these types.)
3838
39-
OK, enough talking; some code will help it make sense. One of the forms of a DU is called a single-case discriminated
40-
union; it can be used to wrap primitives to make them more meaningful. We'll create the following single-case DUs:
39+
To start, bring the `Entities.fs` file over from Tres, and ensure `Quatro.fsproj` has the JSON.Net dependency. Then,
40+
some code will help all this DU stuff make sense. One of the forms of a DU is called a single-case discriminated union;
41+
it can be used to wrap primitives to make them more meaningful. We'll create the following single-case DUs at the top
42+
of the file, before our other types:
4143
*)
4244
type CategoryId = CategoryId of string
4345
type CommentId = CommentId of string
@@ -145,7 +147,7 @@ with
145147
access\*\*, just `Status = Draft`. (`Status = Spam` does not compile.)
146148
147149
You can
148-
[review the entire set of types](https://github.com/danieljsummers/FromObjectsToFunctions/tree/step-2/src/4-Freya-FSharp/Entities.fs)
150+
[review the entire set of types](https://github.com/danieljsummers/FromObjectsToFunctions/tree/step-2-core2/src/4-Freya-FSharp/Entities.fs)
149151
to see where these various DUs were used. While we could certainly take this much further, these simple changes have
150152
made our types more meaningful, while eliminating a lot of the invalid states we could have assigned in our code.
151153

dox/content/step2/tres.fsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ with
1919
As we make the leap to F#, we're changing things around significantly. Remember our
2020
[discussion about the flat structure of an F# project](../step1/tres.html)? Instead of an `Entities` directory with a
2121
lot of little files, we'll define a single `Entities.fs` file in the root of the project. Don't forget to add it to
22-
the list of compiled files in `project.json`; it should go above `HomeModule.fs`.
22+
the list of compiled files in `Tres.fsproj`; it should go above `HomeModule.fs`. Also, while we're in there, we'll add
23+
the JSON.Net dependency in the `ItemGroup` for dependencies:
24+
25+
[lang=text]
26+
<PackageReference Include="Newtonsoft.Json" Version="10.*" />
2327
2428
Next up, we will change the static classes that we created to eliminate magic strings into modules. The
2529
`AuthorizationLevel` type in C# looked like:
@@ -151,7 +155,7 @@ operations you would expect, but there are some differences.
151155
- While not demonstrated here, arrays are defined between `[|` `|]` pairs, also with elements separated by semicolons.
152156
153157
Before continuing on to [Quatro](quatro.html), you should familiarize yourself with the
154-
[types in this step](https://github.com/danieljsummers/FromObjectsToFunctions/tree/step-2/src/3-Nancy-FSharp/Entities.fs).
158+
[types in this step](https://github.com/danieljsummers/FromObjectsToFunctions/tree/step-2-core2/src/3-Nancy-FSharp/Entities.fs).
155159
156160
[Back to Step 2](../step2)
157161
*)

dox/content/step2/uno-dos.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ that will actually be stored in the database are `Category`, `Comment`, `Page`,
66
`Revision` and `Authorization` give structure to the collections stored within other objects (`Page`/`Post` and
77
`User`, respectively).
88

9+
To support the `JsonProperty` attribute, we'll need to add a reference to JSON.Net; this goes in the `.csproj` file, in
10+
the `ItemGroup` with dependencies:
11+
12+
[lang=text]
13+
<PackageReference Include="Newtonsoft.Json" Version="10.*" />
14+
915
If you're reading through this for learning, you'll want to familiarize yourself with the
10-
[files as they are in C# at this step](https://github.com/danieljsummers/FromObjectsToFunctions/tree/step-2/src/1-AspNetCore-CSharp/Entities)
16+
[files as they are in C# at this step](https://github.com/danieljsummers/FromObjectsToFunctions/tree/step-2-core2/src/1-AspNetCore-CSharp/Entities)
1117
before continuing to [Tres](tres.html) and [Quatro](quatro.html).
1218

1319
[Back to Step 2](../step2)

0 commit comments

Comments
 (0)