private void InitializePools() { initialized = true; Pools = new List <MonoMemoryPool <TViewModel, T> >(); if (memoryPoolSettings == null) { memoryPoolSettings = new MemoryPoolSettings(10, 100, PoolExpandMethods.Double); } //Logger.Log($"Creating {nameof(ViewPoolContainer<T, TViewModel>)}"); foreach (GameObject prefab in prefabList) { //Logger.Log($"Creating Pool for View type {nameof(T)}"); if (prefab.GetComponent <T>() != null) { var pool = diContainer.Instantiate <PoolableViewPool <TViewModel, T> >(new object[] { memoryPoolSettings, new ComponentFromPrefabFactory <T>(prefab, diContainer) }); Pools.Add(pool); } else { Debug.LogError("Prefab without correct view given to ViewPoolContainer."); } } }
protected override void OnFinalizeBinding(DiContainer container) { var factory = new FactoryProviderWrapper <TContract>( _factoryBindInfo.ProviderFunc(container), new InjectContext(container, typeof(TContract))); var settings = new MemoryPoolSettings( _poolBindInfo.InitialSize, _poolBindInfo.MaxSize, _poolBindInfo.ExpandMethod); var transientProvider = new TransientProvider( _factoryBindInfo.FactoryType, container, _factoryBindInfo.Arguments.Concat( InjectUtil.CreateArgListExplicit(factory, settings)).ToList(), BindInfo.ContextInfo, BindInfo.ConcreteIdentifier, null); IProvider mainProvider; if (BindInfo.Scope == ScopeTypes.Unset || BindInfo.Scope == ScopeTypes.Singleton) { mainProvider = BindingUtil.CreateCachedProvider(transientProvider); } else { Assert.IsEqual(BindInfo.Scope, ScopeTypes.Transient); mainProvider = transientProvider; } RegisterProviderForAllContracts(container, mainProvider); }
public ViewPoolContainer(GameObject[] prefabs, DiContainer container, MemoryPoolSettings poolSettings = null) { prefabList = prefabs; diContainer = container; memoryPoolSettings = poolSettings; }
public void TestFromRuntime() { var settings = new MemoryPoolSettings(0, int.MaxValue, PoolExpandMethods.OneAtATime); var pool = Container.Instantiate <Qux.Pool>(new object[] { settings, new CustomFactory() }); var qux = pool.Spawn(); Assert.IsEqual(pool.NumTotal, 1); }
void Construct( IAsyncGenericAssetFactory <TKey, TContract> factory, DiContainer container, [InjectOptional] MemoryPoolSettings settings) { // MemoryPoolSettings InitialSize affects stack initial size _settings = settings ?? MemoryPoolSettings.Default; _factory = factory; _container = container; _inactiveItems = new Dictionary <TKey, Stack <TContract> >(); _activeCount = new Dictionary <TKey, int>(); }
public void Initialize() { for (int i = 0; i < PrefabList.Length; i++) { Prefab = PrefabList[i]; if (Prefab.GetComponent <T>() != null) { MemoryPoolSettings = new MemoryPoolSettings(InitialPoolSizes[i], 100, PoolExpandMethods.OneAtATime); var pool = DiContainer.Instantiate <PoolableMonoPool <T> >(new object[] { MemoryPoolSettings, new ComponentFromPrefabFactory <T>(Prefab, DiContainer) }); Pools.Add(pool); } else { Debug.LogError($"Prefab without correct component given to ViewPoolContainer. With name {Prefab.name}. Component wanted is of type {typeof(T)}"); } } Debug.Log($"PoolContainer Initialized, Pool count: {Pools.Count}"); }