Search in sources :

Example 1 with Ioc

use of com.blade.ioc.Ioc in project blade by biezhi.

the class NettyServer method initIoc.

private void initIoc() {
    RouteMatcher routeMatcher = blade.routeMatcher();
    routeMatcher.initMiddleware(blade.middleware());
    routeBuilder = new RouteBuilder(routeMatcher);
    blade.scanPackages().stream().flatMap(DynamicContext::recursionFindClasses).map(ClassInfo::getClazz).filter(ReflectKit::isNormalClass).forEach(this::parseAndCreate);
    routeMatcher.register();
    this.loaders.stream().sorted(new OrderComparator<>()).forEach(b -> b.preLoad(blade));
    this.processors.stream().sorted(new OrderComparator<>()).forEach(b -> b.preHandle(blade));
    Ioc ioc = blade.ioc();
    if (BladeKit.isNotEmpty(ioc.getBeans())) {
        log.info("{}Register bean: {}", getStartedSymbol(), ioc.getBeans());
    }
    List<BeanDefine> beanDefines = ioc.getBeanDefines();
    if (BladeKit.isNotEmpty(beanDefines)) {
        beanDefines.forEach(b -> {
            IocKit.initInjection(ioc, b);
            IocKit.injectionValue(environment, b);
            List<TaskStruct> cronExpressions = BladeKit.getTasks(b.getType(), environment);
            if (null != cronExpressions) {
                taskStruts.addAll(cronExpressions);
            }
        });
    }
    this.loaders.stream().sorted(new OrderComparator<>()).forEach(b -> b.load(blade));
    this.processors.stream().sorted(new OrderComparator<>()).forEach(b -> b.processor(blade));
}
Also used : RouteBuilder(com.blade.mvc.route.RouteBuilder) RouteMatcher(com.blade.mvc.route.RouteMatcher) TaskStruct(com.blade.task.TaskStruct) OrderComparator(com.blade.ioc.bean.OrderComparator) Ioc(com.blade.ioc.Ioc) BeanDefine(com.blade.ioc.bean.BeanDefine) ClassInfo(com.blade.ioc.bean.ClassInfo)

Example 2 with Ioc

use of com.blade.ioc.Ioc in project tale by otale.

the class Bootstrap method preLoad.

@Override
public void preLoad(Blade blade) {
    Ioc ioc = blade.ioc();
    Validators.useChinese();
    boolean devMode = true;
    if (blade.environment().hasKey("app.dev")) {
        devMode = blade.environment().getBoolean("app.dev", true);
    }
    if (blade.environment().hasKey("app.devMode")) {
        devMode = blade.environment().getBoolean("app.devMode", true);
    }
    SqliteJdbc.importSql(devMode);
    Anima.open(SqliteJdbc.DB_SRC);
    Commons.setSiteService(ioc.getBean(SiteService.class));
}
Also used : SiteService(com.tale.service.SiteService) Ioc(com.blade.ioc.Ioc)

Aggregations

Ioc (com.blade.ioc.Ioc)2 BeanDefine (com.blade.ioc.bean.BeanDefine)1 ClassInfo (com.blade.ioc.bean.ClassInfo)1 OrderComparator (com.blade.ioc.bean.OrderComparator)1 RouteBuilder (com.blade.mvc.route.RouteBuilder)1 RouteMatcher (com.blade.mvc.route.RouteMatcher)1 TaskStruct (com.blade.task.TaskStruct)1 SiteService (com.tale.service.SiteService)1