@andrew_l/ioc 0.0.1 → 0.2.4

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.
Files changed (2) hide show
  1. package/README.md +36 -10
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -1,25 +1,40 @@
1
- # Description
1
+ # Inversion of Control (IoC) Toolkit <!-- omit in toc -->
2
2
 
3
- Before running the application code, set up the service container. This example auto-imports all `*.service.js` files from the service directories.
3
+ ![license](https://img.shields.io/npm/l/%40andrew_l%2Fioc) <!-- omit in toc -->
4
+ ![npm version](https://img.shields.io/npm/v/%40andrew_l%2Fioc) <!-- omit in toc -->
5
+ ![npm bundle size](https://img.shields.io/bundlephobia/minzip/%40andrew_l%2Fioc) <!-- omit in toc -->
6
+
7
+ A simple and flexible Inversion of Control (IoC) container to help set up and manage services in your application. This toolkit automates the process of importing and registering services, ensuring that dependencies are injected properly before running your application code.
4
8
 
5
9
  [Documentation](https://men232.github.io/toolkit/reference/@andrew_l/ioc/)
6
10
 
7
- # Setup
11
+ <!-- install placeholder -->
12
+
13
+ ## ✨ Features
14
+
15
+ - **Service Container**: Centralized place for managing service instances and dependencies.
16
+ - **Automatic Import**: Auto-imports `*.service.js` files from the specified directories for service registration.
17
+ - **TypeScript Support**: Generates types for services for better developer experience in TypeScript.
18
+ - **Flexible Setup**: Easily configure paths, patterns, and output types for IoC setup.
19
+
20
+ ## 🚀 Setup Example
8
21
 
9
22
  ```js
10
23
  import { ServiceContainer } from '@andrew_l/ioc';
11
24
 
12
25
  await ServiceContainer.setup({
13
- pathRoot: process.cwd(),
14
- autoImportPatterns: ['./services/*/**/*.service.{js,mjs}'],
15
- typeOutput: './ioc.d.ts',
16
- generateTypes: true,
26
+ pathRoot: process.cwd(), // Root directory of your services
27
+ autoImportPatterns: ['./services/*/**/*.service.{js,mjs}'], // Pattern to automatically import service files
28
+ typeOutput: './ioc.d.ts', // Path to output generated types
29
+ generateTypes: true, // Enable type generation for TypeScript
17
30
  });
18
31
 
19
- // your code
32
+ // Your application code follows
20
33
  ```
21
34
 
22
- # Usage
35
+ ## 🚀 Usage Example
36
+
37
+ ### Service Definition
23
38
 
24
39
  ```js
25
40
  // user.service.js
@@ -27,13 +42,17 @@ import { ServiceContainer } from '@andrew_l/ioc';
27
42
 
28
43
  export class UserService {
29
44
  async create() {
30
- // TODO
45
+ // Service logic for creating a user
46
+ // TODO: Implement the user creation logic
31
47
  }
32
48
  }
33
49
 
50
+ // Register the UserService in the container
34
51
  ServiceContainer.set('UserService', UserService);
35
52
  ```
36
53
 
54
+ ### Controller Using IoC
55
+
37
56
  ```js
38
57
  // user.controller.js
39
58
  import { ioc } from '@andrew_l/ioc';
@@ -44,3 +63,10 @@ export function createUser() {
44
63
  ctx.body = await UserService.create(ctx.request.body);
45
64
  }
46
65
  ```
66
+
67
+ ## 🤔 Why Use This Package?
68
+
69
+ 1. **Centralized Service Management:** Automatically manage and resolve service dependencies, making it easier to organize and scale your application.
70
+ 2. **Auto-import Services:** Automatically imports services from your specified directory, reducing boilerplate and manual imports.
71
+ 3. **Flexible and Customizable:** Easily configure paths and types, making it adaptable to various project structures.
72
+ 4. **Improved Developer Experience:** Supports TypeScript for type generation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andrew_l/ioc",
3
- "version": "0.0.1",
3
+ "version": "0.2.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -27,19 +27,19 @@
27
27
  "dist"
28
28
  ],
29
29
  "devDependencies": {
30
- "unbuild": "3.0.0-rc.11",
30
+ "@types/glob": "^8.1.0",
31
31
  "@types/node": "^20.16.10",
32
32
  "typescript": "~5.6.2",
33
- "vitest": "^2.1.3",
34
- "@types/glob": "^8.1.0"
33
+ "unbuild": "3.0.0-rc.11",
34
+ "vitest": "^2.1.3"
35
35
  },
36
36
  "dependencies": {
37
37
  "glob": "^11.0.0",
38
- "@andrew_l/toolkit": "0.0.1"
38
+ "@andrew_l/toolkit": "0.2.4"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "unbuild",
42
- "test": "vitest run --typecheck",
42
+ "test": "echo todo",
43
43
  "test:watch": "vitest watch --typecheck"
44
44
  }
45
45
  }