Skip to content

Commit

Permalink
feat(examples): add poc for inversify plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mildronize committed Apr 17, 2024
1 parent 9cf2273 commit 7d57029
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { inject } from 'inversify';
import { func } from '../nammatham';
import { DataService } from '../services/data.service';

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

hello = func
.httpGet('hello', {
Expand Down
21 changes: 17 additions & 4 deletions examples/azure-functions-with-inversify/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import 'reflect-metadata';
import { expressPlugin } from 'nammatham';
import { BaseHandlerResolver, expressPlugin, NammathamApp } from 'nammatham';
import { HomeController } from './controllers/home.controller';
import { app } from './nammatham';
import { container } from './container';
import { DataService } from './services/data.service';
import { Container, interfaces } from 'inversify';

const homeController = new HomeController(container.get(DataService));
app.addFunctions(homeController.hello);
// Uncomment this line to use inversify plugin
// import { inverisfyPlugin } from '@nammatham/inversify';

// Mock inversify plugin
declare function inverisfyPlugin(options: {
container: Container;
controllers: interfaces.ServiceIdentifier[];
}): (app: NammathamApp, handlerResolver: BaseHandlerResolver) => void;

// Manually register controllers
// const homeController = new HomeController(container.get(DataService));
// app.addFunctions(homeController.hello);

// Automatically register controllers
app.register(inverisfyPlugin({ container, controllers: [HomeController] }));

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

0 comments on commit 7d57029

Please sign in to comment.