Controller Types
There are two types of controllers standalone and non-standalone controllers.
The main difference between both of them that standalone controller is an independendent controller and does not require an AscModule to work and host HTTP endpoints.
Standalone Controllers
Standalone controllers don't require an AscModule to access dependency injection scope. You can directly import modules or define and use providers right in the controller itself by managing them in the @Controller decorator itself
Here's the example with SupplierController:
As same as AscModule has parameters that manage it's dependency injection, a standalone controller has it too.
- importscan contain other modules or controllers to import to, their- exportswill be imported and exposed to current controller's scope
- providersdefines providers that will be available only for this controller's dependency injection scope unless you won't explicitly export them by including them in- exports
- exportsallows to export providers or imported providers, declarations to other module/controller that will import this controller
Tip
Read more about Dependency Injection in AscModules at the AscModule Guide Page
Non-Standalone Controllers
This type of controllers require a parent AscModule to define them as their declaration. As a non-standalone controller will be defined in declarations of an AscModule it becomes the controller of that module which declared it in their declarations. It also becomes consumer of the module as it can access it's dependency injection scope and import available dependencies to that module
Here's the example with non-standalone SupplierController:
Now, SupplierController is controller and subject of an AscModule SupplierModule. SupplierController can access DI scope of SupplierModule and use it's defined and imported providers
- importscan contain other modules or controllers to import to, their- exportswill be imported and exposed to current controller's scope
- providersdefines providers that will be available only for this controller's dependency injection scope unless you won't export them by including them in- exports
- exportsallows to export providers or imported providers, declarations to other module/controller that will import this controller
Tip
Read more about Dependency Injection in AscModules at the AscModule Guide Page