Skip to content

Commit 60a5c24

Browse files
update readme with the details about new controller inheritance feature
1 parent dd4e9f0 commit 60a5c24

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ You can use routing-controllers with [express.js][1] or [koa.js][2].
5555
+ [Interceptor classes](#interceptor-classes)
5656
+ [Global interceptors](#global-interceptors)
5757
* [Creating instances of classes from action params](#creating-instances-of-classes-from-action-params)
58+
* [Controller inheritance](#controller-inheritance)
5859
* [Auto validating action params](#auto-validating-action-params)
5960
* [Using authorization features](#using-authorization-features)
6061
- [@Authorized decorator](#authorized-decorator)
@@ -1236,6 +1237,33 @@ Learn more about class-transformer and how to handle more complex object constru
12361237
This behaviour is enabled by default.
12371238
If you want to disable it simply pass `classTransformer: false` to createExpressServer method. Alternatively you can disable transforming for [individual controllers or routes](#selectively-disable-requestresponse-transforming).
12381239

1240+
## Controller Inheritance
1241+
Often your application may need to have an option to inherit controller from another to reuse code and void duplication.
1242+
A good example of the use is the CRUD operations which can be hidden inside `AbstractBaseController` with the possibility to add new and overload methods, the template method pattern.
1243+
1244+
```typescript
1245+
@Controller(`/product`)
1246+
class ProductController extends AbstractControllerTemplate {}
1247+
@Controller(`/category`)
1248+
class CategoryController extends AbstractControllerTemplate {}
1249+
abstract class AbstractControllerTemplate {
1250+
@Post()
1251+
public create() {}
1252+
1253+
@Read()
1254+
public read() {}
1255+
1256+
@Put()
1257+
public update() {}
1258+
1259+
@Delete()
1260+
public delete() {}
1261+
}
1262+
1263+
```
1264+
https://en.wikipedia.org/wiki/Template_method_pattern
1265+
1266+
12391267
## Auto validating action params
12401268

12411269
Sometimes parsing a json object into instance of some class is not enough.

0 commit comments

Comments
 (0)