21 lines
810 B
TypeScript
21 lines
810 B
TypeScript
import SessionFactory from './SessionFactory.ts'
|
|
import SessionInterface from './SessionInterface.ts'
|
|
import {Model} from '../../../../orm/src/model/Model.ts'
|
|
import {StaticClass} from '../../../../di/src/type/StaticClass.ts'
|
|
import {isInstantiable} from '../../../../di/src/type/Instantiable.ts'
|
|
|
|
export default class ModelSessionFactory extends SessionFactory {
|
|
constructor(
|
|
protected readonly ModelClass: StaticClass<SessionInterface, typeof Model>,
|
|
) {
|
|
super()
|
|
}
|
|
|
|
produce(dependencies: any[], parameters: any[]): SessionInterface {
|
|
if ( isInstantiable<SessionInterface>(this.ModelClass) )
|
|
return new this.ModelClass() as SessionInterface
|
|
else
|
|
throw new TypeError(`Session model class ${this.ModelClass} is not instantiable.`)
|
|
}
|
|
}
|