tsioc
Version:
tsioc is AOP, Ioc container, via typescript decorator
67 lines (65 loc) • 4.52 kB
JavaScript
;
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
var index_1 = require("../utils/index");
var index_2 = require("./decorators/index");
var index_3 = require("./actions/index");
var DefaultLifeScope_1 = require("./DefaultLifeScope");
var types_1 = require("../types");
var ActionFactory_1 = require("./ActionFactory");
var index_4 = require("./factories/index");
var MethodAccessor_1 = require("./MethodAccessor");
var ProviderMatcher_1 = require("./ProviderMatcher");
var index_5 = require("./providers/index");
var CacheManager_1 = require("./CacheManager");
__export(require("./actions/index"));
__export(require("./decorators/index"));
__export(require("./factories/index"));
__export(require("./providers/index"));
__export(require("./ActionFactory"));
__export(require("./DefaultLifeScope"));
__export(require("./ProviderMatcher"));
__export(require("./MethodAccessor"));
__export(require("./CacheManager"));
/**
* register core for container.
*
* @export
* @param {IContainer} container
*/
function registerCores(container) {
container.registerSingleton(index_1.symbols.LifeScope, function () { return new DefaultLifeScope_1.DefaultLifeScope(container); });
container.register(index_5.ProviderMap, function () { return new index_5.ProviderMap(container); });
container.registerSingleton(index_1.symbols.ICacheManager, function () { return new CacheManager_1.CacheManager(container); });
container.registerSingleton(index_1.symbols.IProviderMatcher, function () { return new ProviderMatcher_1.ProviderMatcher(container); });
container.registerSingleton(index_1.symbols.IMethodAccessor, function () { return new MethodAccessor_1.MethodAccessor(container); });
var factory = new ActionFactory_1.ActionFactory();
var lifeScope = container.get(index_1.symbols.LifeScope);
lifeScope.addAction(factory.create(index_3.CoreActions.beforeConstructor), index_4.DecoratorType.Class);
lifeScope.addAction(factory.create(index_3.CoreActions.afterConstructor), index_4.DecoratorType.Class);
lifeScope.addAction(factory.create(index_3.CoreActions.bindProvider), index_4.DecoratorType.Class, types_1.IocState.design);
lifeScope.addAction(factory.create(index_3.CoreActions.bindPropertyType), index_4.DecoratorType.Property);
lifeScope.addAction(factory.create(index_3.CoreActions.injectProperty), index_4.DecoratorType.Property);
lifeScope.addAction(factory.create(index_3.CoreActions.bindParameterType), index_4.DecoratorType.Parameter);
lifeScope.addAction(factory.create(index_3.CoreActions.bindParameterProviders), index_4.DecoratorType.Parameter);
lifeScope.addAction(factory.create(index_3.CoreActions.componentBeforeInit), index_4.DecoratorType.Class, index_3.CoreActions.afterConstructor);
lifeScope.addAction(factory.create(index_3.CoreActions.componentInit), index_4.DecoratorType.Property);
var cacheAction = factory.create(index_3.CoreActions.componentCache);
lifeScope.addAction(cacheAction, index_4.DecoratorType.Class, index_3.CoreActions.componentCache);
lifeScope.registerDecorator(index_2.Injectable, index_3.CoreActions.bindProvider, index_3.CoreActions.componentCache);
lifeScope.registerDecorator(index_2.Component, index_3.CoreActions.bindProvider, index_3.CoreActions.componentCache, index_3.CoreActions.componentBeforeInit, index_3.CoreActions.componentInit);
lifeScope.registerDecorator(index_2.Singleton, index_3.CoreActions.bindProvider);
lifeScope.registerDecorator(index_2.Abstract, index_3.CoreActions.bindProvider, index_3.CoreActions.componentCache);
lifeScope.registerDecorator(index_2.AutoWired, index_3.CoreActions.bindParameterType, index_3.CoreActions.bindPropertyType);
lifeScope.registerDecorator(index_2.Inject, index_3.CoreActions.bindParameterType, index_3.CoreActions.bindPropertyType);
lifeScope.registerDecorator(index_2.Param, index_3.CoreActions.bindParameterType, index_3.CoreActions.bindPropertyType);
lifeScope.registerDecorator(index_2.Method, index_3.CoreActions.bindParameterProviders);
container.register(Date, function () { return new Date(); });
container.register(String, function () { return ''; });
container.register(Number, function () { return Number.NaN; });
container.register(Boolean, function () { return undefined; });
}
exports.registerCores = registerCores;
//# sourceMappingURL=../sourcemaps/core/index.js.map