Skip to content

Commit 1a528c6

Browse files
author
craigparra
committed
1.0.11 / 2021-08-10
================== * Add Application cdi support - @craigparra
1 parent e34de8d commit 1a528c6

File tree

8 files changed

+84
-5401
lines changed

8 files changed

+84
-5401
lines changed

Application.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const { ApplicationContext } = require('@alt-javascript/cdi');
2+
const Boot = require('./Boot');
3+
4+
module.exports = class Application {
5+
static run(optionsArg) {
6+
const options = optionsArg;
7+
if (!Boot.root('config')) {
8+
Boot.boot(options);
9+
}
10+
options.config = options?.config || Boot.root('config');
11+
let applicationContext = options?.applicationContext || options;
12+
if (applicationContext.constructor.name !== 'ApplicationContext') {
13+
applicationContext = new ApplicationContext(options);
14+
}
15+
applicationContext.lifeCycle();
16+
return applicationContext;
17+
}
18+
};

History.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
1.0.11 / 2021-08-10
2+
==================
3+
4+
* Add Application cdi support - @craigparra
5+
16
1.0.10 / 2021-08-05
27
==================
38

README.md

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,47 @@ An Extensible Config & Logging Application Bootstrap Function
1010
<a name="intro">Introduction</a>
1111
--------------------------------
1212
An opinionated application config and logging bootstrap that streamlines the use of the
13-
- [@alt-javascript/config](https://www.npmjs.com/package/@alt-javascript/config), and
14-
- [@alt-javascript/logger](https://www.npmjs.com/package/@alt-javascript/logger)
13+
- [@alt-javascript/config](https://www.npmjs.com/package/@alt-javascript/config),
14+
- [@alt-javascript/logger](https://www.npmjs.com/package/@alt-javascript/logger), and
15+
- [@alt-javascript/cdi](https://www.npmjs.com/package/@alt-javascript/cdi)
1516

17+
The `Application` class implements a familiar application context and dependency injection
18+
(cdi) implementation, supporting simple singleton and prototype component factory definitions, with a choice of
19+
manual or auto wiring (injection) of property references and config placeholders.
1620

17-
The boot function binds a global root context with configured LoggerFactory
21+
The `Application` class extends the standalone `boot` function, which binds a global root context with configured LoggerFactory
1822
to negate the need for requiring and injecting the application config in every module, and optionally the `node-fetch`
1923
implementation for config pulled from a service url.
20-
24+
25+
The `config`, `loggerFactory`, `LoggerCategoryCache` are registered as injectable singleton components, and the `logger`
26+
is an injectable prototype. See the [@alt-javascript/cdi](https://www.npmjs.com/package/@alt-javascript/cdi) package for more
27+
detail on how the dependency injection works.
28+
2129
<a name="usage">Usage</a>
2230
-------------------------
2331

24-
To use the module, substitute the named {config} module export, in place of the popular
32+
The following example bootstraps an Application with an EmphemeraConfig (but could easily be a regular config
33+
or alt-javascript/config instance), with a basic config context component definition.
34+
35+
```javascript
36+
const ephemeralConfig = new EphemeralConfig(
37+
{
38+
context: {
39+
SimpleClass: {
40+
require: './test/service/SimpleClass',
41+
},
42+
},
43+
},
44+
);
45+
46+
const applicationContext = Application.run({ config: ephemeralConfig });
47+
48+
const simpleClass = applicationContext.get('simpleClass');
49+
assert.exists(simpleClass, 'simpleClass exists');
50+
51+
```
52+
53+
To use the module boot function standalone, substitute the named {config} module export, in place of the popular
2554
[config](https://www.npmjs.com/package/config) default, and `boot` it &ndash; note, we use a named export for config,
2655
because the module exports other useful classes as well.
2756

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const Boot = require('./Boot');
2+
const Application = require('./Application');
23

4+
module.exports.Application = Application;
35
module.exports.Boot = Boot;
46
module.exports.boot = Boot.boot;
57
module.exports.root = Boot.root;

0 commit comments

Comments
 (0)