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
Copy file name to clipboardExpand all lines: _posts/2024-04-19-dotnet8-template.md
+15-6Lines changed: 15 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,18 +13,27 @@ author_staff_member: han
13
13
hide_header_image: true
14
14
---
15
15
16
-
We created a new template for C# and .NET 8.0. The template is based on the ASP.NET Core [Minimal API](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis?view=aspnetcore-8.0).
16
+
We have created a new OpenFaaS template for C# and .NET 8.0 and it's based on the [Minimal API](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis?view=aspnetcore-8.0) of ASP.NET Core.
17
17
18
-
In the past we had an official csharp that used the original forking mode of the OpenFaaS watchdog, which created one process per request, and was less efficient than newer templates where one process would handle many requests concurrently. There were also a number of unofficial templates adopted by the community, which were not necessarily kept up to date, or something that we could support directly.
18
+
In the past we provided a basic `csharp` template that used the original forking mode of the OpenFaaS watchdog, which created one process per request, and was less efficient than newer templates where one process would handle many requests concurrently.
19
+
20
+
There were also a number of unofficial templates adopted by the community, which were not necessarily kept up to date, or something that we could support directly.
19
21
20
22
The new template is called: `dotnet8-csharp` and has the following benefits:
21
23
22
24
- Adding NuGet packages to a function for additional dependencies.
23
25
- Register services for dependency injection
24
-
- Using ASP.NET Core middleware
26
+
- Uses the latest ASP.NET Core middleware
27
+
- Based upon the highly-performant Kestrel HTTP server
25
28
26
29
In the next section we will walk through an example that show you how to develop and deploy an OpenFaaS function with C# and the new template.
27
30
31
+
In function will read rows from a database table, and return them as JSON.
32
+
33
+
We'll then briefly discuss a few other features like dependency injection and how to use ASP.NET middlewares such as the static fileserver.
34
+
35
+
OpenFaaS templates provide a handler, some way to add dependencies, and a build system to create an OCI compatible image. But if you're already building your own images, you can deploy them to OpenFaaS if they provide a HTTP server. See also: [Build ASP.NET Core APIs with Kubernetes and OpenFaaS](https://www.openfaas.com/blog/asp-net-core/)
36
+
28
37
## Prerequisites
29
38
30
39
We won't go into detail on how to deploy OpenFaaS and assume you are already running OpenFaaS on Kubernetes or on a VM with [faasd](https://github.com/openfaas/faasd). Check out the [deployment guide](https://docs.openfaas.com/deployment/) for more information.
@@ -36,14 +45,14 @@ In this section we will walk through an example showing how to create a function
36
45
37
46
We will assume you are already running a Postgres database somewhere. You can use one of the many DBaaS services available, run a postgres with docker or use [arkade](https://github.com/alexellis/arkade) to quickly deploy a database in your cluster. If you are running faasd, the official guide [Serverless For Everyone Else](https://openfaas.gumroad.com/l/serverless-for-everyone-else) has a chapter that shows how to deploy PostgreSQL as an additional service.
38
47
39
-
To quickly deploy PostgreSQL in your Kubernetes cluster run`arkade install postgresql`. After the installation it will print out all the instructions to get the password and connect to the database.
48
+
You could use a managed PostgreSQL service from AWS, GCP, DigitalOcean, etc, or deploy a development version of PostgreSQL into your Kubernetes cluster using`arkade install postgresql`. After the installation it will print out all the instructions to get the password and connect to the database.
40
49
41
50
We will create a table and insert some records that can be queried by our function:
42
51
43
52
```sql
44
53
CREATETABLEIF NOT EXISTS employee
45
54
(
46
-
id INTPRIMARY KEYNOT NULL,
55
+
id INTPRIMARY KEYNOT NULL,
47
56
name TEXTNOT NULL,
48
57
email TEXTNOT NULL
49
58
);
@@ -174,7 +183,7 @@ faas-cli up
174
183
175
184
Invoking the function should return a json response that looks like this:
0 commit comments