Giter VIP home page Giter VIP logo

enterpriseazurefunctions's Introduction

Injectable, Composable, Testable TypeScript Azure Functions

... That also run locally and could run in AWS Lamba.

This project is a sample of how one might go about building a nicely composed TypeScript based, testable, IOC based codebase for working with Azure Functions or other similar technologies.

constructor(@inject(contracts.contractSymbols.ICognitiveService) cognitiveService:contracts.ICognitiveService) {
        super();
        this._cognitiveService = cognitiveService;
    }

Publish and consume dependencies in a nice way

Most samples are basic. Sure they get the job done, but in reality when we want to write production code, we may like to follow some of the regular tenets of software design like SOLID, IOC and importantly testability + what ever other acronym or initialism you may like to throw at it.

This code sample is meant to be a starter project to help with that.

It has a single HttpTrigger that will take an image and run it against some Microsoft Cognitive Services. Super simple, but it gets the point across.

It has:

  • Loosly coupled dependencies that are exposed via Dependency Injection using Inversify
  • Some basic tests using Ava that support mocking and stubbing using Sinon
  • Neat workflows using TSC watchmode, Nodemon and Ava watch mode.
  • Code adapts to run inside Azure Functions or locally using Restify. Loggers etc will work becasue dependencies will reflect where the code is running.

The DI container is built in startup.ts and run via CognitiveRun/app.ts which will be exposed as an Azure Function when deployed.

You can add your own services in startup.ts. For a good example of a injectable component see netClient.ts. It gets registered here in startup.ts. Don't forget to add interfaces and Symbols (needed fro Inversify) in contracts.ts.

I prefer to edit/run/edit using TSC watch mode and nodemon.

Open a terminal and run npm run watch to fire up TSC watch. This will output things to output/run.

Open another terminal and run npm run outputwatch. This will fire up the system with nodemon which will check for changes and restart the app as needed.

Open yet another terminal and run npm run testwatchbuild which will run a TSC watch on the test src files.

Now in a final termianl (or a separate powershell window on another screen perhaps) run npm run testwatchava which will auto run tests on changed files as you edit them.

Now you can run your code in postman and you can also do some TDD, or just write test to help you dev - however you like to work :)

enterpriseazurefunctions's People

Contributors

jakkaj 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.