first-di 3.3.2 → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +141 -0
- package/CODE_OF_CONDUCT.md +132 -0
- package/CONTRIBUTING.md +144 -0
- package/README.md +73 -40
- package/package.json +10 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [3.4.1] - 2025-12-07
|
|
6
|
+
|
|
7
|
+
### ⚙️ Miscellaneous Tasks
|
|
8
|
+
|
|
9
|
+
- Remove .npmignore and update package.json to include additional files
|
|
10
|
+
- Clean up husky scripts and enhance README with security policy and features
|
|
11
|
+
|
|
12
|
+
## [3.4.0] - 2025-12-07
|
|
13
|
+
|
|
14
|
+
## [3.3.2] - 2025-07-17
|
|
15
|
+
|
|
16
|
+
### ⚙️ Miscellaneous Tasks
|
|
17
|
+
|
|
18
|
+
- Update dependencies and improve code quality
|
|
19
|
+
|
|
20
|
+
## [3.3.1] - 2025-04-10
|
|
21
|
+
|
|
22
|
+
### 🐛 Bug Fixes
|
|
23
|
+
|
|
24
|
+
- Correct capitalization and grammar in documentation and comments
|
|
25
|
+
|
|
26
|
+
## [3.3.0] - 2025-04-10
|
|
27
|
+
|
|
28
|
+
### 🚀 Features
|
|
29
|
+
|
|
30
|
+
- Update dependencies versions
|
|
31
|
+
|
|
32
|
+
## [3.2.2] - 2025-01-03
|
|
33
|
+
|
|
34
|
+
### ⚙️ Miscellaneous Tasks
|
|
35
|
+
|
|
36
|
+
- Update node build version to 23
|
|
37
|
+
|
|
38
|
+
## [3.2.1] - 2025-01-03
|
|
39
|
+
|
|
40
|
+
### 🧪 Testing
|
|
41
|
+
|
|
42
|
+
- Replace mocha by native test runner
|
|
43
|
+
|
|
44
|
+
## [3.2.0] - 2025-01-03
|
|
45
|
+
|
|
46
|
+
### 🚀 Features
|
|
47
|
+
|
|
48
|
+
- Update dependencies versions, use new eslint 9 config
|
|
49
|
+
|
|
50
|
+
## [3.1.0] - 2024-10-05
|
|
51
|
+
|
|
52
|
+
### 🚀 Features
|
|
53
|
+
|
|
54
|
+
- Update dependencies versions
|
|
55
|
+
|
|
56
|
+
## [3.0.1] - 2024-06-02
|
|
57
|
+
|
|
58
|
+
### ⚙️ Miscellaneous Tasks
|
|
59
|
+
|
|
60
|
+
- Ci without force
|
|
61
|
+
|
|
62
|
+
## [3.0.0] - 2024-06-02
|
|
63
|
+
|
|
64
|
+
### 🚀 Features
|
|
65
|
+
|
|
66
|
+
- [**breaking**] Moke package type module
|
|
67
|
+
- Update readme for new ecmascript decorator standart, deprecate @autowired decorator
|
|
68
|
+
- Begin generate changelog by cliff-jumper, deploy over github actions
|
|
69
|
+
|
|
70
|
+
### 🐛 Bug Fixes
|
|
71
|
+
|
|
72
|
+
- Bump dependencies
|
|
73
|
+
- Bump version and publish to npm
|
|
74
|
+
- Bump dependencies
|
|
75
|
+
- Bump version and publish to npm
|
|
76
|
+
- Bump dependencies
|
|
77
|
+
- Bump version and publish to npm
|
|
78
|
+
- Bump dependencies
|
|
79
|
+
- Bump version and publish to npm
|
|
80
|
+
- Bump dependencies
|
|
81
|
+
- Bump version and publish to npm
|
|
82
|
+
|
|
83
|
+
### 📚 Documentation
|
|
84
|
+
|
|
85
|
+
- Clean readme from autowired decorator information
|
|
86
|
+
|
|
87
|
+
### ⚙️ Miscellaneous Tasks
|
|
88
|
+
|
|
89
|
+
- Bump dependencies
|
|
90
|
+
- Bump version and publish to npm
|
|
91
|
+
- Bump dependencies
|
|
92
|
+
- Bump version and publish to npm
|
|
93
|
+
- Bump dependencies
|
|
94
|
+
- Bump version and publish to npm
|
|
95
|
+
- Bump dependencies
|
|
96
|
+
- Bump version and publish to npm
|
|
97
|
+
- Bump dependencies
|
|
98
|
+
- Bump version and publish to npm
|
|
99
|
+
- Disable src from npm package
|
|
100
|
+
- Bump dependencies
|
|
101
|
+
- Bump version and publish to npm
|
|
102
|
+
- Bump dependencies
|
|
103
|
+
- Bump version and publish to npm
|
|
104
|
+
- Bump dependencies
|
|
105
|
+
- Bump version and publish to npm
|
|
106
|
+
- Fix new eslint in tests
|
|
107
|
+
- Bump dependencies
|
|
108
|
+
- Bump version and publish to npm
|
|
109
|
+
- Bump dependencies
|
|
110
|
+
- Bump version and publish to npm
|
|
111
|
+
- Bump dependencies
|
|
112
|
+
- Bump version and publish to npm
|
|
113
|
+
- Bump dependencies
|
|
114
|
+
- Bump version and publish to npm
|
|
115
|
+
- Bump dependencies
|
|
116
|
+
- Bump version and publish to npm
|
|
117
|
+
- Fix styles for new eslint version
|
|
118
|
+
- Bump dependencies
|
|
119
|
+
- Bump version and publish to npm
|
|
120
|
+
- Bump dependencies
|
|
121
|
+
- Bump version and publish to npm
|
|
122
|
+
- Bump dependencies
|
|
123
|
+
- Bump version and publish to npm
|
|
124
|
+
- Update code style for new codestyle config
|
|
125
|
+
- Bump dependencies
|
|
126
|
+
- Bump version and publish to npm
|
|
127
|
+
- Bump dependencies
|
|
128
|
+
- Bump version and publish to npm
|
|
129
|
+
- Update packages versions
|
|
130
|
+
- Bump dependencies
|
|
131
|
+
- Bump version and publish to npm
|
|
132
|
+
- Bump dependencies
|
|
133
|
+
- Bump version and publish to npm
|
|
134
|
+
- Bump dependencies
|
|
135
|
+
- Bump version and publish to npm
|
|
136
|
+
- Bump dependencies
|
|
137
|
+
- Bump version and publish to npm
|
|
138
|
+
- Bump dependencies
|
|
139
|
+
- Bump version and publish to npm
|
|
140
|
+
- Add CHANGELOG.md
|
|
141
|
+
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
|
10
|
+
identity and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
|
26
|
+
community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
|
31
|
+
any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
|
35
|
+
without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official e-mail address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
labeg@mail.ru or [discord server](https://discordapp.com/channels/974049080454045796/974049142022209566).
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
|
86
|
+
actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
|
93
|
+
ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
|
113
|
+
community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.1, available at
|
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by
|
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
123
|
+
|
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
|
127
|
+
|
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Contributing to @labeg/code-style
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing! This document provides guidelines for contributing to this project.
|
|
4
|
+
|
|
5
|
+
## Code of Conduct
|
|
6
|
+
|
|
7
|
+
By participating in this project, you agree to abide by our [Code of Conduct](./CODE_OF_CONDUCT.md).
|
|
8
|
+
|
|
9
|
+
## How to Contribute
|
|
10
|
+
|
|
11
|
+
### Reporting Bugs
|
|
12
|
+
|
|
13
|
+
Before creating bug reports, please check the existing issues. When creating a bug report, include:
|
|
14
|
+
|
|
15
|
+
- **Clear title and description**
|
|
16
|
+
- **Steps to reproduce** the problem
|
|
17
|
+
- **Expected behavior** vs **actual behavior**
|
|
18
|
+
- **Code samples** that demonstrate the issue
|
|
19
|
+
- **Environment details** (Node.js version, npm version, OS)
|
|
20
|
+
|
|
21
|
+
### Suggesting Enhancements
|
|
22
|
+
|
|
23
|
+
Enhancement suggestions are welcome! Please provide:
|
|
24
|
+
|
|
25
|
+
- **Clear description** of the enhancement
|
|
26
|
+
- **Use cases** and why it would be useful
|
|
27
|
+
- **Possible implementation** approach (if you have ideas)
|
|
28
|
+
|
|
29
|
+
### Pull Requests
|
|
30
|
+
|
|
31
|
+
1. **Fork the repository** and create your branch from `master`
|
|
32
|
+
2. **Make your changes** following our coding standards
|
|
33
|
+
3. **Test your changes** by running `npm test`
|
|
34
|
+
4. **Commit your changes** using [Conventional Commits](https://www.conventionalcommits.org/):
|
|
35
|
+
- `feat:` for new features
|
|
36
|
+
- `fix:` for bug fixes
|
|
37
|
+
- `docs:` for documentation changes
|
|
38
|
+
- `chore:` for maintenance tasks
|
|
39
|
+
- `refactor:` for code refactoring
|
|
40
|
+
5. **Push to your fork** and submit a pull request
|
|
41
|
+
|
|
42
|
+
## Development Setup
|
|
43
|
+
|
|
44
|
+
### Prerequisites
|
|
45
|
+
|
|
46
|
+
- Node.js (latest LTS version recommended)
|
|
47
|
+
- npm or pnpm
|
|
48
|
+
|
|
49
|
+
### Setup Steps
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
# Clone your fork
|
|
53
|
+
git clone https://github.com/YOUR_USERNAME/code-style.git
|
|
54
|
+
cd code-style
|
|
55
|
+
|
|
56
|
+
# Install dependencies
|
|
57
|
+
npm install
|
|
58
|
+
|
|
59
|
+
# Run tests
|
|
60
|
+
npm test
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Coding Standards
|
|
64
|
+
|
|
65
|
+
This project follows its own ESLint rules! Key principles:
|
|
66
|
+
|
|
67
|
+
### Code Style
|
|
68
|
+
|
|
69
|
+
- **Line length**: Maximum 120 characters
|
|
70
|
+
- **Indentation**: 4 spaces
|
|
71
|
+
- **Quotes**: Use double quotes `"` or template literals `` ` ``
|
|
72
|
+
- **Semicolons**: Always use semicolons
|
|
73
|
+
- **Braces**: Always use braces for control structures
|
|
74
|
+
|
|
75
|
+
### Example
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
// Good
|
|
79
|
+
if (condition) {
|
|
80
|
+
doSomething();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const message = `Hello ${name}`;
|
|
84
|
+
|
|
85
|
+
// Bad
|
|
86
|
+
if (condition) doSomething();
|
|
87
|
+
|
|
88
|
+
const message = 'Hello ' + name;
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Commit Messages
|
|
92
|
+
|
|
93
|
+
Follow [Conventional Commits](https://www.conventionalcommits.org/):
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
feat: add support for new ESLint rule
|
|
97
|
+
fix: correct TypeScript configuration issue
|
|
98
|
+
docs: update README with new examples
|
|
99
|
+
chore: upgrade dependencies
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Testing
|
|
103
|
+
|
|
104
|
+
Before submitting your PR:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# Run ESLint tests
|
|
108
|
+
npm test
|
|
109
|
+
|
|
110
|
+
# Check for security vulnerabilities
|
|
111
|
+
npm audit
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
All tests must pass before your PR can be merged.
|
|
115
|
+
|
|
116
|
+
## Review Process
|
|
117
|
+
|
|
118
|
+
1. **Automated checks** run on every PR (tests, linting, security)
|
|
119
|
+
2. **Manual review** by maintainers
|
|
120
|
+
3. **Feedback** may be provided - please address comments
|
|
121
|
+
4. **Approval** - once approved, your PR will be merged
|
|
122
|
+
|
|
123
|
+
## Release Process
|
|
124
|
+
|
|
125
|
+
Releases are automated:
|
|
126
|
+
|
|
127
|
+
1. Maintainer merges PR to `master`
|
|
128
|
+
2. Version is bumped automatically
|
|
129
|
+
3. Changelog is generated
|
|
130
|
+
4. Package is published to npm
|
|
131
|
+
5. GitHub release is created
|
|
132
|
+
|
|
133
|
+
## Questions?
|
|
134
|
+
|
|
135
|
+
- Open an issue with the `question` label
|
|
136
|
+
- Check existing issues and discussions
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
By contributing, you agree that your contributions will be licensed under the MIT License.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
Thank you for contributing to @labeg/code-style! 🎉
|
package/README.md
CHANGED
|
@@ -1,34 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
=====
|
|
1
|
+
# first-di
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/first-di)
|
|
4
|
+
[](https://www.npmjs.com/package/first-di)
|
|
5
|
+
[](https://github.com/LabEG/first-di/blob/master/LICENSE)
|
|
6
|
+
[](https://github.com/LabEG/first-di/actions)
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
Lightweight and powerful dependency injection container for TypeScript applications
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Overview
|
|
13
|
+
|
|
14
|
+
**first-di** is a modern, type-safe dependency injection container designed specifically for TypeScript applications. It provides a clean and intuitive API for managing dependencies with minimal configuration and zero runtime dependencies.
|
|
15
|
+
|
|
16
|
+
### Key Features
|
|
17
|
+
|
|
18
|
+
- 🚀 **Zero Dependencies** - No external runtime dependencies required
|
|
19
|
+
- 💡 **Two Operation Modes** - Optional DI for simplicity, Classic DI for advanced scenarios
|
|
20
|
+
- 🔄 **Multiple Lifecycles** - Singleton, Transient, Per-Instance, and Per-Access patterns
|
|
21
|
+
- 🎯 **Type-Safe** - Full TypeScript support with decorator-based metadata
|
|
22
|
+
- 🔧 **Flexible Scoping** - Support for multiple isolated DI containers
|
|
23
|
+
- 🧪 **Test-Friendly** - Easy mocking and overriding for unit tests
|
|
24
|
+
- 📦 **Extensible** - Built on OOP/SOLID principles for easy customization
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
8
29
|
|
|
9
30
|
For the latest stable version:
|
|
10
31
|
|
|
11
|
-
```
|
|
32
|
+
```bash
|
|
12
33
|
npm i first-di
|
|
13
34
|
```
|
|
14
35
|
|
|
15
|
-
|
|
16
|
-
------
|
|
36
|
+
## Quick Start
|
|
17
37
|
|
|
18
|
-
|
|
19
|
-
- 2 modes of work. Optional DI - for most apps. Classic DI - for advanced apps.
|
|
20
|
-
- Support for multiple scopes.
|
|
21
|
-
- Supports multiple life cycles.
|
|
22
|
-
- Dependency-free. Dependencies are used only for development.
|
|
38
|
+
### Prerequisites
|
|
23
39
|
|
|
24
|
-
|
|
25
|
-
------
|
|
40
|
+
Install [reflect-metadata](https://www.npmjs.com/package/reflect-metadata) package and import it in your application entry point:
|
|
26
41
|
|
|
27
|
-
|
|
42
|
+
```bash
|
|
43
|
+
npm install reflect-metadata
|
|
44
|
+
```
|
|
28
45
|
|
|
29
|
-
|
|
46
|
+
Enable the following compiler options in `tsconfig.json`:
|
|
30
47
|
|
|
31
|
-
```
|
|
48
|
+
```json
|
|
32
49
|
{
|
|
33
50
|
"compilerOptions": {
|
|
34
51
|
...
|
|
@@ -40,10 +57,13 @@ In tsconfig.json enable compiler options:
|
|
|
40
57
|
|
|
41
58
|
```
|
|
42
59
|
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Usage
|
|
63
|
+
|
|
64
|
+
### Optional DI Mode
|
|
45
65
|
|
|
46
|
-
|
|
66
|
+
The simplest approach - write classes and inject dependencies through constructors. All dependencies are automatically resolved when calling `resolve()`.
|
|
47
67
|
|
|
48
68
|
```typescript
|
|
49
69
|
import { resolve, override, reflection } from "first-di";
|
|
@@ -109,10 +129,9 @@ if (process.env.NODE_ENV === "test") {
|
|
|
109
129
|
}
|
|
110
130
|
```
|
|
111
131
|
|
|
112
|
-
|
|
113
|
-
------
|
|
132
|
+
### Classic DI Mode
|
|
114
133
|
|
|
115
|
-
|
|
134
|
+
For advanced scenarios, use abstract classes as contracts instead of interfaces. Abstract classes generate runtime metadata that TypeScript interfaces cannot provide.
|
|
116
135
|
|
|
117
136
|
```typescript
|
|
118
137
|
import { resolve, override, reflection } from "first-di";
|
|
@@ -193,8 +212,7 @@ if (process.env.NODE_ENV === "test") {
|
|
|
193
212
|
}
|
|
194
213
|
```
|
|
195
214
|
|
|
196
|
-
Options
|
|
197
|
-
------
|
|
215
|
+
## Options
|
|
198
216
|
|
|
199
217
|
First DI has several points for customizing dependency options:
|
|
200
218
|
|
|
@@ -214,8 +232,7 @@ Options have the following properties:
|
|
|
214
232
|
|
|
215
233
|
PER_ACCESS - Create new instance on each access to resolved property.
|
|
216
234
|
|
|
217
|
-
Scopes
|
|
218
|
-
------
|
|
235
|
+
## Scopes
|
|
219
236
|
|
|
220
237
|
Support multiple scopes
|
|
221
238
|
|
|
@@ -233,18 +250,21 @@ const serviceScopeB = scopeB.resolve(ProductionService);
|
|
|
233
250
|
const dataB = await serviceScopeB.getData();
|
|
234
251
|
```
|
|
235
252
|
|
|
236
|
-
|
|
237
|
-
------
|
|
253
|
+
---
|
|
238
254
|
|
|
239
|
-
|
|
255
|
+
## API Reference
|
|
240
256
|
|
|
241
|
-
|
|
242
|
-
- resolve - Function. Resolves dependency with default options or specified.
|
|
243
|
-
- singleton - Function. Resolve singleton.
|
|
244
|
-
- instance - Function. Resolve new instance.
|
|
245
|
-
- reset - Function. Reset all singleton list and override list, but doesn't reset global options.
|
|
257
|
+
### Core Functions
|
|
246
258
|
|
|
247
|
-
|
|
259
|
+
- **`override(fromClass, toClass, options?)`** - Override dependency resolution with custom implementation
|
|
260
|
+
- **`resolve(class, options?)`** - Resolve dependency with specified or default options
|
|
261
|
+
- **`singleton(class)`** - Resolve as singleton instance
|
|
262
|
+
- **`instance(class)`** - Always create new instance
|
|
263
|
+
- **`reset()`** - Clear all singletons and overrides (preserves global options)
|
|
264
|
+
|
|
265
|
+
### Service Locator Pattern
|
|
266
|
+
|
|
267
|
+
The API functions can be used to implement the Service Locator pattern:
|
|
248
268
|
|
|
249
269
|
```typescript
|
|
250
270
|
import { singleton, instance, resolve, AutowiredLifetimes } from "first-di";
|
|
@@ -260,10 +280,13 @@ class ApiDemo {
|
|
|
260
280
|
}
|
|
261
281
|
```
|
|
262
282
|
|
|
263
|
-
|
|
264
|
-
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## Advanced Usage
|
|
265
286
|
|
|
266
|
-
|
|
287
|
+
### Extending the DI Container
|
|
288
|
+
|
|
289
|
+
Built on OOP and SOLID principles, every component can be extended or customized:
|
|
267
290
|
|
|
268
291
|
```typescript
|
|
269
292
|
import { DI } from "first-di";
|
|
@@ -275,3 +298,13 @@ class MyDI extends DI {
|
|
|
275
298
|
}
|
|
276
299
|
}
|
|
277
300
|
```
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## Contributing
|
|
305
|
+
|
|
306
|
+
Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) and [Code of Conduct](CODE_OF_CONDUCT.md) before submitting pull requests.
|
|
307
|
+
|
|
308
|
+
## License
|
|
309
|
+
|
|
310
|
+
MIT © [Eugene Labutin](https://github.com/LabEG)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "first-di",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"author": "Eugene Labutin",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/LabEG/first-di#readme",
|
|
@@ -8,6 +8,14 @@
|
|
|
8
8
|
"main": "./dist/index.js",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"typings": "./dist/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE",
|
|
15
|
+
"CHANGELOG.md",
|
|
16
|
+
"CODE_OF_CONDUCT.md",
|
|
17
|
+
"CONTRIBUTING.md"
|
|
18
|
+
],
|
|
11
19
|
"repository": {
|
|
12
20
|
"type": "git",
|
|
13
21
|
"url": " git@github.com:LabEG/first-di.git"
|
|
@@ -28,7 +36,7 @@
|
|
|
28
36
|
"build": "rm -rf dist/ && tsc --project tsconfig.build.json && node ./dist/index.js",
|
|
29
37
|
"release": "cliff-jumper --name 'first-di' --package-path '.' --no-skip-changelog --no-skip-tag",
|
|
30
38
|
"prepublishOnly": "npm run lint && npm run build && npm run test",
|
|
31
|
-
"prepare": "husky
|
|
39
|
+
"prepare": "husky"
|
|
32
40
|
},
|
|
33
41
|
"peerDependencies": {
|
|
34
42
|
"reflect-metadata": ">=0.1.0"
|