Bundle `ContainerModule` for [inversify](https://github.com/inversify/InversifyJS). Co-located module bundling solution.
Bundle ContainerModule for inversify.
Co-located module bundling solution.
```
npm i -D @rym-lib/inversify-bundler
`ts
interface ExamplePort {}
@injectable()
class Example implements ExamplePort {
constructor(
@inject(DBIdentifier)
private db: DBPort,
) {}
}
const { identifier: ExampleIdentifier, bundler: ExampleModule } =
createModule
export { ExampleIdentifier, ExampleModule }
export type { ExamplePort }
`
`ts
import { ExampleModule, ExamplePort, ExampleIdentifier } from './example'
const container = new Container()
container.load(...ExampleModule.resolve())
const example = container.get
`
`ts`
const { identifier, bundler } = createModule
'UserRegister',
UserRegisterInteraction,
[PrismaModule, LoggerModule],
)
`ts
import { ContainerModule as InversifyContainerModule } from 'inversify'
import { ContainerModule, ModuleBundler } from '@rym-lib/inversify-bundler'
import { LoggerModule } from '~/logger'
import { prisma } from '~/my-prisma'
const name = 'Prisma'
const prismaIdentifier = Symbol.for(name)
const redisIdentifier = Symbol.for('Redis')
const bundler = new Bundler(
LoggerModule,
new ContainerModule(
(bind) => {
bind
},
{ name },
),
new InversifyContainerModule((bind) => {
bind
}),
)
`
resolve() exclude duplicate module and return flat ContainerModule array.
But, can not resolve in already registered container's modules. Use child container.
`ts
import { Container } from 'inversify'
import { bundler } from '~/my-module'
const container = new Container()
container.load(...bundler.resolve())
``