Giter VIP home page Giter VIP logo

calculator's Introduction

Calculator

Calculator is a Azure Serverless Function

Azure Functions documentation

Software System Requirements

  1. As a developer, I want to create a new HTTP serverless function and test my new function locally, so that it is ready to be deployed to the Azure Cloud.
  2. As a developer, I want to add dependency injection to my function, so that I can utilize services or 3rd party libraries.
  3. As a DevOps Engineer, I want to package and deploy my serverless function to the Azure cloud, so that I allow my team to perform integration tests.

Pre-requisites

    Azure Subscription

    .Net 6 SDK

    Visual Studio Code

    Azure Function Core Tools 4x - Azure Functions Core Tools

    Azure CLI - Azure Command-line Interface (CLI)

Steps to create the Azure Function Project and function types

  1. Create new project. I created a new project in GitHub named Calculator. I cloned my new Calculator project to my local desktop.
  2. Navigate into the new Calculator project directory .
  3. Optional: Initialize git flow. From the Calculator directory, I initialized Git Flow using the following command:
git flow init
  1. Generate new Azure Function App. I used the Azure Function Core CLI to generate the new function app.
func init Kulba.Function.Calculator --dotnet
  1. Create a new HTTP function type. Navigate into the new directory Kulba.Function.Calculator that was created in the previous step. Here is another example of the Azure Function Core CLI command to generate the HTTP function. The generator uses the name value to create the new class and to name the function. The template value describes the name of the function. And the authlevel describes the execution security scope.
func new --name Sum --template "HTTP trigger" --authlevel "function"
  1. Add Serilog packages to project.
dotnet add package Microsoft.Azure.Functions.Extensions
dotnet add package Serilog
dotnet add package Serilog.Extensions.Logging
dotnet add package Serilog.Sinks.Console
dotnet add package Serilog.Sinks.File
  1. Initialize Serilog in the Program.cs
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;

var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()

    .ConfigureServices(services =>
    {
        var logger = new LoggerConfiguration()
        .WriteTo.Console()
        .WriteTo.File("log.txt", rollingInterval: RollingInterval.Day)
        .CreateLogger();
        services.AddLogging(lb => lb.AddSerilog(logger));
    })
    .Build();

host.Run();

Additional Azure Function Resources

Offical Microsoft Azure Functions

DotNet SDK CLI Templates

  1. Visual Studio 2022 has the Azure Functions project templates already installed.
  2. To install the additional Azure Function templates. This gives you the developer the awesome power to create new function apps and function types from the DotNet SDK CLI. This is important if you want to use Visual Studio Code.

Function Project Templates

dotnet new --install Microsoft.Azure.Functions.Worker.ProjectTemplates

calculator's People

Contributors

jkulba avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.