Getting Started
unioc
is a unified IoC (Inversion of Control) framework written in TypeScript, aiming to unify the TypeScript ecosystem's IoC frameworks. With a simple plugin system, it can integrate with any TS ecosystem's IoC framework (such as Nest.js
, Midway
), enabling ecosystem sharing.
Project Architecture
Currently, unioc
is still under active development. Below is the architecture diagram of the core
and backend
components of unioc
:
Below is the architecture diagram of the backend
components of unioc
:
Installation
Install unioc
via package manager:
# Using npm
npm install unioc
# Using yarn
yarn add unioc
# Using pnpm
pnpm add unioc
Basic Usage
Creating a Basic Application
Here is a simple Express application example:
import { ExpressApp } from 'unioc/web-express'
async function bootstrap() {
// Create an Express application
const app = await new ExpressApp()
// Run the application
await app.run(3000)
}
bootstrap()
Integrating with Nest.js
If you already have a Nest.js project, you can easily migrate to unioc
:
import process from 'node:process'
import { NestJS } from 'unioc/adapter-nestjs'
import { ExpressApp } from 'unioc/web-express'
import { AppModule } from './app.module'
async function bootstrap() {
// Create an Express application
const app = await new ExpressApp()
// Use the NestJS adapter and import your main module
app.use(NestJS, {
imports: [AppModule],
})
// Run the application
await app.run(process.env.PORT || 3000)
}
bootstrap()
Unified Decorators
unioc
provides decorator factories that are compatible with both legacy and stage3 environments:
import { defineClassDecorator } from 'unioc/decorator'
function MyClassDecorator() {
return defineClassDecorator({
onClassDecorate(target) {
// Implement your logic
}
})
}
@MyClassDecorator()
class MyClass {}
Plugin System
unioc
provides a rollup-like plugin system that allows complete control over an application's startup, runtime, and destruction processes.
Next Steps
NOTE
unioc
is currently under active development. If you have any questions or suggestions, please contact us through GitHub Issues or Discord.