open-index/open-npm huggingface dataset:
npm package: @kanian77/simple-di
Description: A simple dependency injection library for TypeScript.
Author: Patrick Assoa Adou
Latest version: 0.1.2

# Dependency Injection System

This project is a TypeScript-based Dependency Injection (DI) system designed to facilitate the management of dependencies in a modular and scalable way. It supports features such as singleton and transient lifecycles, autowiring of dependencies, and custom token names for services.

## Features

- **Service Registration**: Register classes or values as services using decorators or direct registration.
- **Autowiring**: Automatically resolve and inject dependencies based on constructor parameters.
- **Singleton and Transient Lifecycles**: Support for singleton (single instance) and transient (new instance per request) service lifecycles.
- **Custom Tokens**: Use strings, symbols, or classes as unique identifiers for services.
- **Module System**: Organize services into modules for better structure and reusability.
- **Value and Factory Providers**: Register static values or use factory functions to create service instances.

## Installation

To install the dependencies, run:

```bash
npm install
```

## Usage

### Registering a Service

Use the `@Service` decorator to register a class as a service:

```typescript
@Service()
class MyService {
  getValue() {
    return 'Hello, World!';
  }
}
```

### Injecting Dependencies

Use the `@Inject` decorator to inject dependencies into a class using tokens:

```typescript
const MY_SERVICE_TOKEN = Symbol('MyServiceToken');

@Service({ token: MY_SERVICE_TOKEN })
class MyService {
  getValue() {
    return 'Hello, World!';
  }
}

@Service()
class ConsumerService {
  constructor(@Inject(MY_SERVICE_TOKEN) private myService: MyService) {}

  getValue() {
    return this.myService.getValue();
  }
}
```

### Transient Services

Transient services are created anew each time they are requested. To define a transient service, specify the lifecycle option as 'transient' in the `@Service` decorator and use a token for registration:

```typescript
const TRANSIENT_SERVICE_TOKEN = Symbol('TransientServiceToken');

@Service({ token: TRANSIENT_SERVICE_TOKEN, lifecycle: 'transient' })
class TransientService {
  public value: number = Math.random();
}

// Usage
const instance1: TransientService = inject(TRANSIENT_SERVICE_TOKEN);
const instance2: TransientService = inject(TRANSIENT_SERVICE_TOKEN);

console.log(instance1.value !== instance2.value); // true, different instances
```

### Initializing the Container

Call `initializeContainer()` to resolve all registered services:

```typescript
initializeContainer();
```

### Using Modules

Define modules to group related services:

```typescript
const myModule = new Module({
  providers: [MyService, ConsumerService],
});
```

### Bootstrapping the Application

Use the `bootstrap` function to initialize the application with a root module:

```typescript
bootstrap(myModule);
```

## Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue.

## License

This project is licensed under the MIT License.
npm package: @kanian77/simple-di-app-generator
Description: generates a @kanian77/simple-di app
Author: Patrick Assoa Adou
Latest version: 0.1.2

# simpledi-app-generator

CLI tool to generate [simple-di](https://www.npmjs.com/package/@kanian77/simple-di) projects with a complete backend architecture.

## Installation

```bash
npm install -g @kanian77/simple-di-app-generator
```

Or link locally for development:

```bash
git clone <repo>
cd simpledi-app-generator
bun install
bun run prepare
npm link
```

## Commands

| Command                                  | Description                           |
| ---------------------------------------- | ------------------------------------- |
| `simpledi new <name>`                    | Create a new simple-di project        |
| `simpledi module <entity>`               | Generate a module with CRUD use cases |
| `simpledi use-case <name> [imports=...]` | Generate a use case with routes       |

## Quick Start

```bash
# Create project
simpledi new my-app
cd my-app
bun install

# Add your DATABASE_URL to .env.development
# Generate entities (includes CRUD use cases!)
simpledi module user
simpledi module blog-post

# Generate custom use cases
simpledi use-case get-dashboard-stats imports=user,blog-post
simpledi use-case publish-post imports=blog-post

# Run
bun run dev
```

## Documentation

See [user-guide.md](./user-guide.md) for complete documentation.

## Project Structure

Generated projects follow this structure:

```
my-project/
├── main.ts              # Entry point
├── config/              # Configuration module
├── db/                  # Database service module
└── src/
    ├── AppModule.ts     # Root module
    ├── schema.ts        # Drizzle schema exports
    ├── main.routes.ts   # Auto-discovers *Routes.{ts,js} files via Bun glob
    ├── core/            # Entity modules (generated)
    ├── lib/             # Utilities, types, errors
    └── use-case/        # Use case modules
```

## Prerequisites

### Neon PostgreSQL

Generated projects use [Neon](https://neon.tech) serverless PostgreSQL. Add your connection string to `.env.development`:

```env
CONNECTION_STRING=postgres://user:password@your-neon-host.neon.tech/dbname?sslmode=require
```

### Environment Variables

| Variable            | Description                       |
| ------------------- | --------------------------------- |
| `CONNECTION_STRING` | Neon PostgreSQL connection string |
| `JWT_SECRET`        | Secret key for JWT tokens         |
| `PORT`              | Server port (default: 3000)       |

## Tech Stack

- **Runtime**: [Bun](https://bun.sh)
- **Framework**: [Hono](https://hono.dev)
- **DI**: [@kanian77/simple-di](https://www.npmjs.com/package/@kanian77/simple-di)
- **ORM**: [Drizzle](https://orm.drizzle.team)
- **Database**: [Neon PostgreSQL](https://neon.tech)
- **Validation**: [Zod](https://zod.dev)

## License

MIT