Skip to content

openfaas/dotnet-templates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

dotnet-templates

Templates for .NET

dotnet8-csharp

This template uses the ASP.net minimal API style, and exposes a static function to register HTTP handlers. It is multi-arch, and supports Linux for amd64 and Arm64 via faas-cli publish or faas-cli up --publish.

Register a /hello as an endpoint:

    public static void MapEndpoints(WebApplication app) {
        app.MapGet("/hello", () => "Hello, world!");
    }

The RegisterServices method can be used to configure any WebApplication services such as Swagger generators.

    public static void MapServices(IServiceCollection services)
    {
        services.AddEndpointsApiExplorer();
        services.AddSwaggerGen();
    }

Pull the template:

faas-cli template pull https://github.com/openfaas/dotnet-templates

Create a new function using the template:

export PREFIX="ttl.sh"
faas-cli new --lang dotnet8-csharp $PREFIX hello-world

Adding static files

If a folder named static is found in the root of your function's source code, it will be copied into the final image published for your function.

To serve the contents of the static folder you can setup the file server in Handler.cs.

    public static void MapEndpoints(WebApplication app) {
        app.UseStaticFiles();
    }

About

Templates for .NET

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published