public T Get(LifetimePolicy lifetime) { T t = null; try { if (CountInactive > 0) { t = m_Available.Pop(); m_Inactive.Remove(t); } else { t = new T(); } KeepTrackOfLifetime(t, lifetime); m_Active.Add(t); m_ActionOnGet?.Invoke(t); } catch (InvalidOperationException) { if (null != t) { // At this point, a list was created, might as well take advantage of it. m_Available.Push(t); m_Inactive.Add(t); m_Active.Remove(t); } throw; } return(t); }
public ContainerObjectDescriptor(Type from, Type to, object instance, LifetimePolicy lifetime) { this.From = from; this.To = to; this.Instance = instance; this.Lifetime = lifetime; }
public void fill(TLVList list) { if (!list.isNull()) { DescribedConstructor constructor = (DescribedConstructor)list.Constructor; _code = (LifetimePolicy)(constructor.getDescriptorCode() & 0x0ff); } }
public IRetryTimeSpecification CreateForPolicy(LifetimePolicy policy) { if (policy != LifetimePolicy.Once) { var periodAndDurationForPolicy = PolicyValues[policy]; return(new PeriodBasedRetryTimeSpecification(periodAndDurationForPolicy.MinimalRetryInterval, periodAndDurationForPolicy.AllowableDuration)); } return(new PeriodBasedRetryTimeSpecification(Period.Zero, Period.Zero)); }
private void KeepTrackOfLifetime(T t, LifetimePolicy lifetime) { switch (lifetime) { case LifetimePolicy.Frame: m_NextFrame.Add(t); break; default: throw new InvalidOperationException($"LifetimePolicy {lifetime} is not supported."); } }
private static LifetimeManager ParseLifetime(LifetimePolicy policy) { if (policy == LifetimePolicy.Singleton) return new ContainerControlledLifetimeManager(); if (policy == LifetimePolicy.Transient) return new TransientLifetimeManager(); if (policy == LifetimePolicy.PerThread) return new PerThreadLifetimeManager(); throw new InvalidOperationException(); }
private static LifetimeManager ParseLifetime(LifetimePolicy policy) { if (policy == LifetimePolicy.Singleton) { return(new ContainerControlledLifetimeManager()); } if (policy == LifetimePolicy.Transient) { return(new TransientLifetimeManager()); } if (policy == LifetimePolicy.PerThread) { return(new PerThreadLifetimeManager()); } throw new InvalidOperationException(); }
public void RegisterType <T>(LifetimePolicy lifetimePolicy, object injectionMembers = null) { InjectionMember[] members = null; MapInjectionMember(ref members, injectionMembers); if (lifetimePolicy == LifetimePolicy.PerThread) { container.RegisterType(typeof(T), typeof(T), string.Empty, new TransientLifetimeManager(), members); } if (lifetimePolicy == LifetimePolicy.Singleton) { container.RegisterType(typeof(T), typeof(T), string.Empty, new ContainerControlledLifetimeManager(), members); } if (lifetimePolicy == LifetimePolicy.Transient) { container.RegisterType(typeof(T), typeof(T), string.Empty, new PerThreadLifetimeManager(), members); } }
public void RegisterType <TFrom, TTo>(string name, LifetimePolicy lifetimePolicy, object injectionMembers = null) where TTo : TFrom { InjectionMember[] members = null; MapInjectionMember(ref members, injectionMembers); if (lifetimePolicy == LifetimePolicy.PerThread) { container.RegisterType(typeof(TFrom), typeof(TTo), name, new TransientLifetimeManager(), members); } if (lifetimePolicy == LifetimePolicy.Singleton) { container.RegisterType(typeof(TFrom), typeof(TTo), name, new ContainerControlledLifetimeManager(), members); } if (lifetimePolicy == LifetimePolicy.Transient) { container.RegisterType(typeof(TFrom), typeof(TTo), name, new PerThreadLifetimeManager(), members); } }
public static Queue <T> Get(LifetimePolicy lifetime = LifetimePolicy.Frame) { return(s_Pool.Get(lifetime)); }
protected abstract IContainerFacade DoRegister(Type from, Type to, string name, LifetimePolicy policy);
public IRetryTimeSpecification CreateForPolicy(LifetimePolicy policy) { return(new PeriodBasedRetryTimeSpecification(Period.FromYears(98), Period.FromYears(99))); }
public IRetryTimeSpecification CreateForPolicy(LifetimePolicy policy) { return(new PeriodBasedRetryTimeSpecification(this._minimalRetryInterval, this._allowableDuration)); }
public IContainerFacade Register <TFrom, TTo>(LifetimePolicy policy) where TTo : TFrom { return(Register(typeof(TFrom), typeof(TTo), null, policy)); }
public static T GetPooled(LifetimePolicy lifetime = LifetimePolicy.Permanent) { return(s_Pool.Get(lifetime)); }
public IContainerFacade Register(Type from, Type to, string name, LifetimePolicy policy) { return(DoRegister(from, to, name, policy)); }
protected override IContainerFacade DoRegister(Type from, Type to, string name, LifetimePolicy policy) { m_Container.RegisterType(from, to, name, ParseLifetime(policy)); return this; }
protected override IContainerFacade DoRegister(Type from, Type to, string name, LifetimePolicy policy) { m_Container.RegisterType(from, to, name, ParseLifetime(policy)); return(this); }
public IContainerFacade Register(Type from, Type to, LifetimePolicy policy) { return(Register(from, to, null, policy)); }
public static HashSet <T> Get(LifetimePolicy lifetime = LifetimePolicy.Frame) { return(s_Pool.Get(lifetime)); }
public static Dictionary <TKey, TValue> Get(LifetimePolicy lifetime = LifetimePolicy.Frame) { return(s_Pool.Get(lifetime)); }
private void Register(Type from, Type to, object instance, LifetimePolicy lifetime) { this.ObjectCollection.Add(from, new ContainerObjectDescriptor(from, to, instance, lifetime)); }
public IRetryTimeSpecification CreateForPolicy(LifetimePolicy policy) { return(new PeriodBasedRetryTimeSpecification(Period.Zero, Period.Zero)); }