Skip to content

Commit

Permalink
feat(examples): add azure-functions inversify class examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mildronize committed Apr 17, 2024
1 parent 18801b7 commit 9cf2273
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 3 deletions.
1 change: 1 addition & 0 deletions examples/azure-functions-with-context/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @examples/azure-functions
15 changes: 15 additions & 0 deletions examples/azure-functions-with-context/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.15.0, 4.0.0)"
}
}
9 changes: 9 additions & 0 deletions examples/azure-functions-with-context/local.settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "node",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
},
"ConnectionStrings": {}
}
27 changes: 27 additions & 0 deletions examples/azure-functions-with-context/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@examples/azure-functions-with-inversify",
"version": "1.0.0",
"description": "",
"main": "dist/src/main.js",
"scripts": {
"build": "tsc",
"lint": "tsc --noEmit",
"start": "tsc && func start",
"dev": "cross-env NODE_ENV=development tsx watch src/main.ts"
},
"author": "Thada Wangthammang",
"license": "MIT",
"dependencies": {
"@azure/functions": "^4.1.0",
"@di-extra/inversify": "^0.2.0",
"nammatham": "2.0.0-alpha.13",
"inversify": "^6.0.2",
"reflect-metadata": "^0.2.1"
},
"devDependencies": {
"cross-env": "^7.0.3",
"npm-run-all": "^4.1.5",
"tsx": "^4.7.0",
"typescript": "^5.0.2"
}
}
6 changes: 6 additions & 0 deletions examples/azure-functions-with-context/src/container.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Container } from 'inversify';
import { DataService } from './services/data.service';

export const container = new Container();
container.bind<DataService>(DataService).toSelf();

10 changes: 10 additions & 0 deletions examples/azure-functions-with-context/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'reflect-metadata';
import { expressPlugin } from 'nammatham';
import hello from './functions/hello';
import { app } from './nammatham';

app.addFunctions(hello);

const dev =process.env.NODE_ENV === 'development';
app.register(expressPlugin({ dev }));
app.start();
7 changes: 7 additions & 0 deletions examples/azure-functions-with-context/src/nammatham.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { initNammatham } from 'nammatham';

const n = initNammatham.create();
n.func;
// ^?
export const func = n.func;
export const app = n.app;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { injectable } from 'inversify';

@injectable()
export class DataService {

public getData() {
return `Data from DataService`;
}
}
13 changes: 13 additions & 0 deletions examples/azure-functions-with-context/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "dist",
"rootDir": ".",
"sourceMap": true,
"strict": true,
"esModuleInterop": true,
"experimentalDecorators": true,
},
"exclude": ["node_modules", "**/*.test.ts"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { func } from '../nammatham';
import { DataService } from '../services/data.service';

export class HomeController {
constructor(public dataService: DataService) {}

hello = func
.httpGet('hello', {
route: 'hello-world',
})
.handler(async c => {
c.context.log('HTTP trigger function processed a request.');

return c.json({
data: 'hello world' + this.dataService.getData(),
});
});
}
9 changes: 6 additions & 3 deletions examples/azure-functions-with-inversify/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'reflect-metadata';
import { expressPlugin } from 'nammatham';
import hello from './functions/hello';
import { HomeController } from './controllers/home.controller';
import { app } from './nammatham';
import { container } from './container';
import { DataService } from './services/data.service';

app.addFunctions(hello);
const homeController = new HomeController(container.get(DataService));
app.addFunctions(homeController.hello);

const dev =process.env.NODE_ENV === 'development';
const dev = process.env.NODE_ENV === 'development';
app.register(expressPlugin({ dev }));
app.start();

0 comments on commit 9cf2273

Please sign in to comment.