mirror of https://gitee.com/bigwinds/arangodb
Deprecated controller.addInjector.
This commit is contained in:
parent
c62573dc5c
commit
5c6484d3ed
|
@ -6,6 +6,7 @@ or are known to become deprecated in a future version of ArangoDB.
|
|||
Deprecated features will likely be removed in upcoming versions of
|
||||
ArangoDB and shouldn't be used if possible.
|
||||
|
||||
|
||||
## 2.5
|
||||
|
||||
* Foxx: method `controller.collection()` has been removed entirely. Please use `appContext.collection()` instead.
|
||||
|
@ -46,7 +47,14 @@ ArangoDB and shouldn't be used if possible.
|
|||
|
||||
|
||||
## 2.8
|
||||
* Foxx: the method `del` of controllers is deprecated, it will raise a warning if you use it. Please use the `delete` method instead.
|
||||
* Foxx: the method `addInjector` of controllers is deprecated, it will raise a warning if you use it. Please use regular variables instead.
|
||||
* Foxx: the property `assets` in manifests has been removed entirely. Please use the `files` property and an external build tool instead.
|
||||
* Foxx: properties `setup` and `teardown` in manifests have been removed entirely. Please use the `scripts` property instead.
|
||||
* The built-in support for CoffeeScript source files has been removed entirely. Please pre-compile CoffeeScript source files.
|
||||
* Simple queries: the following simple query functions will be removed: collection.near(), collection.within(), collection.geo(), collection.fulltext(), collection.range(), collection.closedRange(). It is recommended to replace calls to these functions with equivalent AQL queries, which are more flexible.
|
||||
|
||||
|
||||
## 2.9
|
||||
* Foxx: the method `del` of controllers has been removed entirely. Please use the `delete` method instead.
|
||||
* Foxx: the method `addInjector` of controllers has been removed entirely. Please use regular variables instead.
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
!CHAPTER Foxx Dependency Injection
|
||||
|
||||
If you have runtime dependencies you want to access in your route handlers but don't want to define at load time (e.g. dependencies between multiple Foxx apps), **FoxxController** allows you to inject these dependencies into your route handlers by adding injectors to it.
|
||||
|
||||
!SECTION Add an injector
|
||||
|
||||
Registers a dependency factory with the controller.
|
||||
|
||||
`controller.addInjector(name, factory)`
|
||||
|
||||
The injected dependency will be available as a property with the chosen **name** on the third argument passed to each route handler.
|
||||
|
||||
If **factory** is a function, it will be called the first time a route of that controller is handled and its result will be injected into each route handler. Otherwise the value will be injected as it is.
|
||||
|
||||
If you want to inject a function as a dependency, you need to wrap it in a function.
|
||||
|
||||
**Parameter**
|
||||
|
||||
* **name**: the name under which the dependency will be available in the route handler
|
||||
* **factory**: a function returning the dependency or an arbitrary value that will be passed as-is
|
||||
|
||||
**Examples**
|
||||
|
||||
```js
|
||||
function myFunc() {
|
||||
return 'Hello';
|
||||
}
|
||||
controller.addInjector('something', function() {return 2;});
|
||||
controller.addInjector('other', 'just a string');
|
||||
controller.addInjector('fn', function() {return myFunc;});
|
||||
|
||||
controller.get('/some/route', function(request, response, injected) {
|
||||
response.json({
|
||||
something: injected.something, // 2
|
||||
other: injected.other, // 'just a string'
|
||||
fn: injected.fn.name // 'myFunc'
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
!SECTION Add multiple injectors
|
||||
|
||||
Registers multiple dependency factories with the controller.
|
||||
|
||||
`controller.addInjector(object)`
|
||||
|
||||
Equivalent to calling **addInjector(name, value)** for each property of the object.
|
||||
|
||||
**Parameter**
|
||||
|
||||
* **object**: an object mapping dependency names to dependency factories
|
||||
|
||||
**Examples**
|
||||
|
||||
```js
|
||||
function myFunc() {
|
||||
return 'Hello';
|
||||
}
|
||||
controller.addInjector({
|
||||
something: function() {return 2;},
|
||||
other: 'just a string',
|
||||
fn: function() {return myFunc;}
|
||||
});
|
||||
|
||||
controller.get('/some/route', function(request, response, injected) {
|
||||
response.json({
|
||||
something: injected.something, // 2
|
||||
other: injected.other, // 'just a string'
|
||||
fn: injected.fn.name // 'myFunc'
|
||||
});
|
||||
});
|
||||
```
|
|
@ -1,15 +0,0 @@
|
|||
!CHAPTER Advanced functions
|
||||
|
||||
This chapter is about the more advanced features of Foxx.
|
||||
It requires that you have understood all chapters before as these are getting rather close to the core of Foxx.
|
||||
|
||||
The first advanced feature of Foxx is to write Foxx exports.
|
||||
They are used to define an internal API that can be used by other Foxxes but is not exposed publicly.
|
||||
One use case for Foxx exports is a user management:
|
||||
You want to have it centralized and accessible by other Foxxes as a shared user-base.
|
||||
Though each Foxx should offer its own customized login and register functionality on top of that and you only want this one exposed.
|
||||
|
||||
So the user management can be implemented using [Exports](../Advanced/Exports.md).
|
||||
|
||||
But you would also like to make use of an application with exports in other Foxxes.
|
||||
The counterpart of exports is [Dependency Injection](../Advanced/Injection.md) described thereafter.
|
|
@ -27,7 +27,7 @@ The file **doodads.js** in the app's base path could look like this:
|
|||
|
||||
```js
|
||||
var Foxx = require('org/arangodb/foxx');
|
||||
var Doodad = Foxx.Model.extend({});
|
||||
class Doodad extends Foxx.Model {}
|
||||
var doodadRepo = new Foxx.Repository(
|
||||
applicationContext.collection('doodads'),
|
||||
{model: Doodad}
|
||||
|
@ -121,7 +121,10 @@ Let's say you want to use the `foxx_exports_example` app from earlier in your ap
|
|||
"name": "foxx_dependencies_example",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"exportsExample": "foxx_exports_example:^1.0.0"
|
||||
"exportsExample": {
|
||||
"name": "foxx_exports_example",
|
||||
"version": "^1.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
|
@ -192,7 +192,7 @@ The dependencies of a mounted app can be adjusted
|
|||
from the admin frontend by clicking the *Dependencies* button in the app details
|
||||
or using the **set-dependencies** command of the **foxx-manager** command-line utility.
|
||||
|
||||
For more information on dependencies see the chapter on Foxx Exports.
|
||||
For more information on dependencies see the chapter on [Foxx Exports](./Exports.md).
|
||||
|
||||
!SUBSECTION Defining controllers
|
||||
|
||||
|
|
|
@ -117,6 +117,7 @@
|
|||
* [Background Tasks](Foxx/Develop/Queues.md)
|
||||
* [Console API](Foxx/Develop/Console.md)
|
||||
* [Metainformation](Foxx/Develop/Manifest.md)
|
||||
* [Exports](Foxx/Develop/Exports.md)
|
||||
* [Documentation](Foxx/Develop/ApiDocumentation.md)
|
||||
* [Production](Foxx/Production/README.md)
|
||||
* [Prod-Mode](Foxx/Production/Productionmode.md)
|
||||
|
@ -125,9 +126,6 @@
|
|||
* [Cluster](Foxx/Cluster/README.md)
|
||||
* [Install](Foxx/Cluster/Install.md)
|
||||
* [Setup & Teardown](Foxx/Cluster/Scripts.md)
|
||||
* [Advanced Features](Foxx/Advanced/README.md)
|
||||
* [Exports](Foxx/Advanced/Exports.md)
|
||||
* [Dependency Injection](Foxx/Advanced/Injection.md)
|
||||
* [ArangoDB's Actions](ArangoActions/README.md)
|
||||
* [Delivering HTML Pages](ArangoActions/HtmlExample.md)
|
||||
* [Json Objects](ArangoActions/JsonExample.md)
|
||||
|
|
|
@ -362,6 +362,7 @@ class Controller {
|
|||
}
|
||||
|
||||
addInjector(name, factory) {
|
||||
deprecated('2.9', '"addInjector" is deprecated, use regular variables instead');
|
||||
if (factory === undefined) {
|
||||
_.extend(this.injectors, name);
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue