示例#1
0
        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));
        }
示例#5
0
        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();
        }
示例#7
0
        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();
        }
示例#8
0
        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);
            }
        }
示例#9
0
        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));
 }
示例#11
0
 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));
 }
示例#14
0
 public IContainerFacade Register <TFrom, TTo>(LifetimePolicy policy) where TTo : TFrom
 {
     return(Register(typeof(TFrom), typeof(TTo), null, policy));
 }
示例#15
0
 public static T GetPooled(LifetimePolicy lifetime = LifetimePolicy.Permanent)
 {
     return(s_Pool.Get(lifetime));
 }
示例#16
0
 public IContainerFacade Register(Type from, Type to, string name, LifetimePolicy policy)
 {
     return(DoRegister(from, to, name, policy));
 }
示例#17
0
 protected override IContainerFacade DoRegister(Type from, Type to, string name, LifetimePolicy policy)
 {
     m_Container.RegisterType(from, to, name, ParseLifetime(policy));
     return this;
 }
示例#18
0
 protected override IContainerFacade DoRegister(Type from, Type to, string name, LifetimePolicy policy)
 {
     m_Container.RegisterType(from, to, name, ParseLifetime(policy));
     return(this);
 }
示例#19
0
 public IContainerFacade Register(Type from, Type to, LifetimePolicy policy)
 {
     return(Register(from, to, null, policy));
 }
示例#20
0
 public static HashSet <T> Get(LifetimePolicy lifetime = LifetimePolicy.Frame)
 {
     return(s_Pool.Get(lifetime));
 }
示例#21
0
 public static Dictionary <TKey, TValue> Get(LifetimePolicy lifetime = LifetimePolicy.Frame)
 {
     return(s_Pool.Get(lifetime));
 }
示例#22
0
 private void Register(Type from, Type to, object instance, LifetimePolicy lifetime)
 {
     this.ObjectCollection.Add(from, new ContainerObjectDescriptor(from, to, instance, lifetime));
 }
示例#23
0
 public IRetryTimeSpecification CreateForPolicy(LifetimePolicy policy)
 {
     return(new PeriodBasedRetryTimeSpecification(Period.Zero, Period.Zero));
 }