diff --git a/TODO.txt b/TODO.txt index 264c4c6..afb5838 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,7 +1,6 @@ static assets middleware view engine -user-defined services internationalization uploads & universal path CLI - view routes, template generation, start server, directives, output, args diff --git a/app/bundle/daton_units.ts b/app/bundle/daton_units.ts index 4ba0195..cdf9c38 100644 --- a/app/bundle/daton_units.ts +++ b/app/bundle/daton_units.ts @@ -7,3 +7,4 @@ export { default as HttpKernelUnit } from '../../lib/src/unit/HttpKernel.ts' export { default as ModelsUnit } from '../../orm/src/ModelsUnit.ts' export { default as HttpServerUnit } from '../../lib/src/unit/HttpServer.ts' export { default as RoutingUnit } from '../../lib/src/unit/Routing.ts' +export { default as ServicesUnit } from '../../lib/src/unit/Services.ts' diff --git a/app/units.ts b/app/units.ts index 1ca7f5d..93113a8 100644 --- a/app/units.ts +++ b/app/units.ts @@ -7,10 +7,12 @@ import { HttpKernelUnit, ModelsUnit, HttpServerUnit, - RoutingUnit + RoutingUnit, + ServicesUnit, } from './bundle/daton_units.ts' export default [ + ServicesUnit, ConfigUnit, DatabaseUnit, ModelsUnit, diff --git a/lib/src/service/ServiceProvider.ts b/lib/src/service/ServiceProvider.ts new file mode 100644 index 0000000..e1caf2c --- /dev/null +++ b/lib/src/service/ServiceProvider.ts @@ -0,0 +1,6 @@ +import AppClass from '../lifecycle/AppClass.ts' +export { Service } from '../../../di/src/decorator/Service.ts' + +export class ServiceProvider extends AppClass { + +} diff --git a/lib/src/unit/Services.ts b/lib/src/unit/Services.ts new file mode 100644 index 0000000..edd54b4 --- /dev/null +++ b/lib/src/unit/Services.ts @@ -0,0 +1,18 @@ +import {InstantiableCanonical} from './InstantiableCanonical.ts' +import {ServiceProvider} from '../service/ServiceProvider.ts' +import {CanonicalDefinition} from './Canonical.ts' + +export default class Services extends InstantiableCanonical { + protected base_path = './app/services' + protected canonical_item = 'service' + protected suffix = '.service.ts' + + public async init_canonical_item(def: CanonicalDefinition) { + const item = await super.init_canonical_item(def) + if ( !(item instanceof ServiceProvider) ) { + throw new TypeError(`Invalid service provider definition: ${def.original_name}. Service providers must extend from Daton's base ServiceProvider class.`) + } + + return item + } +}