public T GetModule <T>() where T : class
        {
            ModuleSearchKeys moduleSearchKeys = ModuleSearchKeys.Allocate <T>();
            object           module           = moduleCache.GetModule(moduleSearchKeys);

            if (module == null)
            {
                module = moduleFactory.CreateModule(moduleSearchKeys);
                moduleCache.AddModule(moduleSearchKeys, module);
            }
            moduleSearchKeys.Release2Pool();
            return(module as T);
        }
        public IEnumerable <T> GetAllModules <T>() where T : class
        {
            var moduleSearchKeys = ModuleSearchKeys.Allocate <T>();
            var modules          = moduleCache.GetAllModules() as IEnumerable <object>;

            if (modules == null || !modules.Any())
            {
                modules = moduleFactory.CreateAllModules() as IEnumerable <object>;
                foreach (var module in modules)
                {
                    moduleCache.AddModule(moduleSearchKeys, module);
                }
            }
            moduleSearchKeys.Release2Pool();
            //用select对modules 里面每个元素进行转型操作
            return(modules.Select(m => m as T));
        }
Exemple #3
0
        public T GetModule <T>() where T : class
        {
            // 申请对象
            var moduleSearchKeys = ModuleSearchKeys.Allocate <T>();

            var module = mCache.GetModule(moduleSearchKeys);

            if (module == null)
            {
                module = mFactory.CreateModule(moduleSearchKeys);

                mCache.AddModule(moduleSearchKeys, module);
            }

            // 回收对象
            moduleSearchKeys.Release2Pool();

            return(module as T);
        }