You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 3, 2024. It is now read-only.
This page serves / will serve as the table of contents for each step of the development process. Below the TOC is a table with comparisons among the 4 projects.
4
+
5
+
**[Step 1](step1)** - Hello World
6
+
Establish a web request response with the least possible / complex code
7
+
8
+
**[Step 2](step2)** - Data Model
9
+
Create the persistent types we'll use for our application
10
+
11
+
**[Step 3](step3)** - RethinkDB Connection
12
+
Configure and prepare a RethinkDB connection for use in our application
13
+
14
+
**Step 4** - Framework Setup
15
+
Create folders / conventions for our application and load some dummy data
16
+
17
+
**Step 5** - Routes
18
+
Establish the URLs that our application will recognize
19
+
20
+
**Step 6** - Views
21
+
Implement the web pages by which our application will display its information
22
+
23
+
**Step 7** - Log In
24
+
Users are important in this application!
25
+
26
+
**Step 8** - Page Publishing and Editing
27
+
Create and edit pages
28
+
29
+
**Step 9** - Post Publishing and Editing
30
+
Finally, we can write some posts!
31
+
32
+
**Step 10** - Categories and Tags
33
+
Handle lists of posts by category or tag
34
+
35
+
**Step 11** - RSS Feeds
36
+
Provide RSS and Atom feeds for our content
37
+
38
+
**Step n** - may be added later (yay, scope creep!)
For this project, we'll also start with `project.json`, bringing in the dependencies we'll need.
4
+
5
+
[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
+
},
11
+
12
+
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:
13
+
14
+
[lang=csharp]
15
+
namespace Dos.Modules
16
+
{
17
+
using Nancy;
18
+
19
+
public class HomeModule : NancyModule
20
+
{
21
+
public HomeModule() : base()
22
+
{
23
+
Get("/", _ => "Hello World from Nancy C#");
24
+
}
25
+
}
26
+
}
27
+
28
+
Since we'll be hosting this with Kestrel (via OWIN), we still need a `Startup.cs`, though its `Configure()` method looks a bit different:
29
+
30
+
[lang=csharp]
31
+
public void Configure(IApplicationBuilder app) =>
32
+
app.UseOwin(x => x.UseNancy());
33
+
34
+
(We need to add a using statement for `Nancy.Owin` so that the `UseNancy()` method is visible.)
35
+
36
+
The `App.cs` file is identical to the one from Uno.
_NOTE: While there is a "web" target for C#, it pulls in a lot of files that I'd rather not go through and explain. We
4
+
will not be using Entity Framework for anything, and though this application will use some of the Identity features of
5
+
ASP.NET Core MVC, we will not be using its membership features. Since all of that is out of scope for this effort, and
6
+
all of this is in the "web" template, we won't use it._ 😃
7
+
8
+
To start, we'll open `project.json` and add the dependencies we'll need:
9
+
10
+
[lang=text]
11
+
"dependencies": {
12
+
"Microsoft.AspNetCore.Owin": "1.0.0",
13
+
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0"
14
+
},
15
+
16
+
`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:
17
+
18
+
[lang=csharp]
19
+
public void Configure(IApplicationBuilder app) =>
20
+
app.Run(async context => await context.Response.WriteAsync("Hello World from ASP.NET Core"));
21
+
22
+
(We put in using statements for `Microsoft.AspNetCore.Builder` to make the `IApplicationBuilder` visible and `Microsoft.AspNetCore.Http` to expose the `WriteAsync()` method on the `Response` object.)
23
+
24
+
We'll rename `Program.cs` to `App.cs`. (Why? Well - why not?) Then, within the `Main()` method, we'll construct a Kestrel instance and run it.
25
+
26
+
[lang=csharp]
27
+
using (var host = new WebHostBuilder().UseKestrel().UseStartup<Startup>().Build())
28
+
{
29
+
host.Run();
30
+
}
31
+
32
+
(Most demos don't show the web host wrapped in a using block; it's `IDisposable`, though, so it's a good idea.)
33
+
34
+
At this point, `dotnet run` should give us a successful startup, and browsing to localhost:5000 returns our greeting.
0 commit comments