Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions QUICKSTART.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
## Installation

```bash
bun add fast-di
bun add fast-injection
```

## Basic Usage

### 1. Simple Service Registration

```typescript
import { Container } from "fast-di";
import { singleton } from "fast-di/decorators";
import { Container } from "fast-injection";
import { singleton } from "fast-injection/decorators";

@singleton()
class Logger {
Expand All @@ -25,14 +25,14 @@ const container = new Container();
container.register(Logger); // Decorator controls lifetime

const logger = container.resolve(Logger);
logger.log("Hello, fast-di!");
logger.log("Hello, fast-injection!");
```

### 2. Dependency Injection with Factories

```typescript
import { Container } from "fast-di";
import { singleton } from "fast-di/decorators";
import { Container } from "fast-injection";
import { singleton } from "fast-injection/decorators";

@singleton()
class Database {
Expand Down Expand Up @@ -68,8 +68,8 @@ console.log(service.getUsers());
### 3. Scoped Containers (for HTTP requests)

```typescript
import { Container } from "fast-di";
import { singleton, scoped, inject } from "fast-di/decorators";
import { Container } from "fast-injection";
import { singleton, scoped, inject } from "fast-injection/decorators";

@singleton()
class Database {
Expand Down Expand Up @@ -104,7 +104,7 @@ await requestScope.dispose();
Use `getGlobalContainer()` to access a shared container instance across your entire application without passing it around:

```typescript
import { getGlobalContainer, resetGlobalContainer, Lifetime } from "fast-di";
import { getGlobalContainer, resetGlobalContainer, Lifetime } from "fast-injection";

// Setup at application startup (e.g., in main.ts)
function setupContainer() {
Expand Down Expand Up @@ -175,7 +175,7 @@ await container.dispose(); // Calls onDispose on all services
### 7. Testing with Mocks

```typescript
import { createTestContainer } from "fast-di/testing";
import { createTestContainer } from "fast-injection/testing";

// In your tests
const container = createTestContainer();
Expand All @@ -198,7 +198,7 @@ const service = container.resolve(UserService);
While decorators are the recommended default, explicit options are useful when:

```typescript
import { Lifetime } from "fast-di";
import { Lifetime } from "fast-injection";

// Override decorator at registration
@singleton()
Expand All @@ -220,8 +220,8 @@ You can use decorators to control service lifetimes and document your code. **De
### 8. Decorator-Based Lifetimes

```typescript
import { Container } from "fast-di";
import { singleton, transient, scoped } from "fast-di/decorators";
import { Container } from "fast-injection";
import { singleton, transient, scoped } from "fast-injection/decorators";

@singleton()
class ConfigService {
Expand Down Expand Up @@ -267,7 +267,7 @@ console.log(logger1 === logger2); // false
### 8. Using @inject for Interface Tokens

```typescript
import { injectable, inject } from "fast-di/decorators";
import { injectable, inject } from "fast-injection/decorators";

const ILogger = Symbol("ILogger");
const IDatabase = Symbol("IDatabase");
Expand Down Expand Up @@ -325,7 +325,7 @@ await service.getUsers();
### 9. Decorators Control Lifetimes

```typescript
import { singleton } from "fast-di/decorators";
import { singleton } from "fast-injection/decorators";

@singleton()
class Database {
Expand Down Expand Up @@ -412,7 +412,7 @@ const service = container.resolve(UserService);
}
```

### Decorator Methods (from "fast-di/decorators")
### Decorator Methods (from "fast-injection/decorators")

- `@injectable()` - Mark class as injectable (transient lifetime)
- `@singleton()` - Mark class as singleton lifetime
Expand Down Expand Up @@ -495,7 +495,7 @@ container.registerFactory(UserService, (c) => {
});

// Or, with decorators and @inject, no factory is needed:
import { singleton, inject } from "fast-di/decorators";
import { singleton, inject } from "fast-injection/decorators";

@singleton()
class UserService {
Expand Down Expand Up @@ -588,4 +588,4 @@ container.registerFactory(ServiceA, (c) => {

---

**fast-di** - Built with ❤️ by [21no.de](https://21no.de) | [MIT License](LICENSE)
**fast-injection** - Built with ❤️ by [21no.de](https://21no.de) | [MIT License](LICENSE)
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# fast-di 🚀
# fast-injection 🚀

Modern, lightweight TypeScript Dependency Injection optimized for Bun runtime.

[![npm version](https://img.shields.io/npm/v/fast-di)](https://www.npmjs.com/package/fast-di)
[![Bundle Size](https://img.shields.io/badge/bundle%20size-%3C5KB-brightgreen)](https://github.com/21no-de/fast-di)
[![npm version](https://img.shields.io/npm/v/fast-injection)](https://www.npmjs.com/package/fast-injection)
[![Bundle Size](https://img.shields.io/badge/bundle%20size-%3C5KB-brightgreen)](https://github.com/21no-de/fast-injection)
[![TypeScript](https://img.shields.io/badge/TypeScript-5.0%2B-blue)](https://www.typescriptlang.org/)
[![Bun](https://img.shields.io/badge/Bun-1.0%2B-orange)](https://bun.sh)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
Expand All @@ -24,7 +24,7 @@ Modern, lightweight TypeScript Dependency Injection optimized for Bun runtime.

## Performance

Fast-DI is optimized for speed with minimal overhead. Here are the key performance metrics:
Fast-Injection is optimized for speed with minimal overhead. Here are the key performance metrics:

| Operation | Ops/Second | Avg Time | Notes |
| -------------------- | ------------- | -------- | -------------------------------- |
Expand Down Expand Up @@ -59,16 +59,16 @@ Run benchmarks yourself: `bun run bench`
## Installation

```bash
bun add fast-di
bun add fast-injection
```

## Quick Start

### Basic Usage

```typescript
import { Container } from "fast-di";
import { singleton, inject } from "fast-di/decorators";
import { Container } from "fast-injection";
import { singleton, inject } from "fast-injection/decorators";

// Step 1: Define your services
// Use @singleton() decorator to mark this class as a singleton
Expand Down Expand Up @@ -106,7 +106,7 @@ const userService = container.resolve(UserService);
### Lifecycle Hooks (Basic)

```typescript
import { Container } from "fast-di";
import { Container } from "fast-injection";

class Cache {
private store = new Map<string, string>();
Expand Down Expand Up @@ -144,8 +144,8 @@ await c.dispose();
### Advanced: Multiple Lifetimes

```typescript
import { Container } from "fast-di";
import { singleton, transient, scoped } from "fast-di/decorators";
import { Container } from "fast-injection";
import { singleton, transient, scoped } from "fast-injection/decorators";

// SINGLETON: One instance shared across the entire application
// Perfect for: configuration, database connections, loggers
Expand Down Expand Up @@ -196,8 +196,8 @@ const ctx3 = anotherScope.resolve(RequestContext);
### Using @inject for Constructor Injection

```typescript
import { Container } from "fast-di";
import { singleton, inject } from "fast-di/decorators";
import { Container } from "fast-injection";
import { singleton, inject } from "fast-injection/decorators";

// Step 1: Define your dependencies
@singleton()
Expand Down Expand Up @@ -279,7 +279,7 @@ bun run bench

## Security

Fast-DI includes multiple security enhancements to protect your applications:
Fast-Injection includes multiple security enhancements to protect your applications:

### Token Validation

Expand All @@ -291,7 +291,7 @@ bun run bench

## Security

Fast-DI implements comprehensive security measures to protect against common vulnerabilities. See [SECURITY.md](SECURITY.md) for detailed information.
Fast-Injection implements comprehensive security measures to protect against common vulnerabilities. See [SECURITY.md](SECURITY.md) for detailed information.

**Key Features:**
- 🛡️ **Prototype Pollution Prevention**: Token validation rejects dangerous property names
Expand Down
10 changes: 5 additions & 5 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Security Enhancements

This document describes the security features and best practices implemented in fast-di to protect against common vulnerabilities.
This document describes the security features and best practices implemented in fast-injection to protect against common vulnerabilities.

## Security Features

Expand Down Expand Up @@ -77,7 +77,7 @@ const result = await container.resolveAsync("api");
**Solution**: Explicit cleanup function for decorator metadata:

```typescript
import { clearDecoratorMetadata, singleton } from "fast-di/decorators";
import { clearDecoratorMetadata, singleton } from "fast-injection/decorators";

// Create dynamic service
@singleton()
Expand Down Expand Up @@ -201,7 +201,7 @@ container.register("prototype", Service); // Throws!
Always dispose containers to prevent resource leaks:

```typescript
import { singleton } from "fast-di/decorators";
import { singleton } from "fast-injection/decorators";

@singleton()
class DatabaseConnection {
Expand Down Expand Up @@ -335,7 +335,7 @@ The security test suite includes:

### Not Protected Against

- **Code Injection**: Fast-di does not validate factory function code
- **Code Injection**: The library does not validate factory function code
- **Dependency Confusion**: Users must ensure correct service registration
- **DoS via Circular Dependencies**: Detected but not prevented (throws error)

Expand All @@ -355,4 +355,4 @@ The security test suite includes:

---

**fast-di** - Built with ❤️ by [21no.de](https://21no.de)
**fast-injection** - Built with ❤️ by [21no.de](https://21no.de)
6 changes: 3 additions & 3 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Fast-DI Performance Benchmarks
# Fast-Injection Performance Benchmarks

This directory contains comprehensive performance benchmarks for the Fast-DI dependency injection container.
This directory contains comprehensive performance benchmarks for the Fast-Injection dependency injection container.

## Running Benchmarks

Expand Down Expand Up @@ -202,7 +202,7 @@ The overhead from these protections is minimal (< 0.01µs per operation) while e

## Comparison with Other DI Containers

Fast-DI is optimized for Bun and provides:
Fast-Injection is optimized for Bun and provides:

- **Ultra-low overhead**: ~0.988µs per transient resolution, ~0.037µs for singletons
- **Excellent singleton performance**: 26.8M ops/sec (explicit), 16.7M ops/sec (decorator)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ async function runComparisonBenchmarks(): Promise<void> {

// Main execution
async function main(): Promise<void> {
console.log("🚀 Fast-DI Performance Benchmarks");
console.log("🚀 Fast-Injection Performance Benchmarks");
console.log(`Running on Bun ${Bun.version}`);
console.log(`Platform: ${process.platform} ${process.arch}`);

Expand Down
2 changes: 1 addition & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/CNAME
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fast-di.21no.de
fast-injection.21no.de
Loading
Loading