package cn.ey.biz.module.system.framework.dynamic_api.core;

import cn.ey.biz.module.system.framework.dynamic_api.core.service.IDynamicRegistry;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class InitializingApi implements ApplicationListener<ApplicationStartedEvent> {

    @Resource
    private AbstractResourceStorage resourceStorage;
    @Resource
    private IDynamicRegistry dynamicRegistry;

    @Override
    public void onApplicationEvent(ApplicationStartedEvent event) {
        resourceStorage.getEntities().forEach(entity -> dynamicRegistry.register(entity));
    }

}
