public object ActivateInstance(IObjectAssemblySpecification registration)
        {
            Cache cache = HttpRuntime.Cache;

            string key      = registration.Key;
            object instance = cache[key];

            if (instance == null)
            {
                lock (_syncRoot)
                {
                    instance = cache[key];
                    if (instance == null)
                    {
                        instance = registration.CreateInstance();

                        if (_expirationTime == Cache.NoAbsoluteExpiration &&
                            _expirationDuration == Cache.NoSlidingExpiration)
                        {
                            _expirationBehavior = CachedItemExpirationBehavior.NeverExpires;
                        }

                        switch (_expirationBehavior)
                        {
                        case CachedItemExpirationBehavior.NeverExpires:
                            cache.Insert(key, instance, _dependencies, Cache.NoAbsoluteExpiration,
                                         Cache.NoSlidingExpiration, _cachePriority, _onRemoveCallback);
                            break;

                        case CachedItemExpirationBehavior.AtScheduledDate:
                            cache.Insert(key, instance, _dependencies, _expirationTime,
                                         Cache.NoSlidingExpiration, _cachePriority, _onRemoveCallback);
                            break;

                        case CachedItemExpirationBehavior.AfterTimeSpan:
                            cache.Insert(key, instance, _dependencies, DateTime.UtcNow.Add(_expirationDuration),
                                         Cache.NoSlidingExpiration, _cachePriority, _onRemoveCallback);
                            break;

                        case CachedItemExpirationBehavior.AfterNotUsedInTimeSpan:
                            cache.Insert(key, instance, _dependencies, Cache.NoAbsoluteExpiration,
                                         _expirationDuration, _cachePriority, _onRemoveCallback);
                            break;
                        }
                    }
                }
            }

            return(instance);
        }
예제 #2
0
        public object ActivateInstance(IObjectAssemblySpecification creator)
        {
            object instance = null;


            if (_localStorage == null)
            {
                _localStorage = new Dictionary <string, object>();
            }

            if (!_localStorage.TryGetValue(creator.Key, out instance))
            {
                instance = creator.CreateInstance();
                _localStorage[creator.Key] = instance;
            }

            return(instance);
        }
예제 #3
0
        public object ActivateInstance(IObjectAssemblySpecification registration)
        {
            object instance;

            if (!RequestLifetimeInstances.TryGetValue(registration.Key, out instance))
            {
                lock (_lock)
                {
                    if (!RequestLifetimeInstances.TryGetValue(registration.Key, out instance))
                    {
                        instance = registration.CreateInstance();
                        RequestLifetimeInstances[registration.Key] = instance;
                    }
                }
            }

            return(instance);
        }
        public object ActivateInstance(IObjectAssemblySpecification registration)
        {
            object instance = Session[registration.Key];

            if (instance == null)
            {
                lock (_syncLock)
                {
                    instance = Session[registration.Key];
                    if (instance == null)
                    {
                        instance = registration.CreateInstance();
                        Session[registration.Key] = instance;
                    }
                }
            }

            return(instance);
        }
예제 #5
0
        public object ActivateInstance(IObjectAssemblySpecification registration)
        {
            string key = registration.Key;

            CachedInstance ci = null;

            if (_cache.TryGetValue(key, out ci))
            {
                lock (_syncLock) ci.LastCacheHit = DateTime.UtcNow;
            }
            else
            {
                ci = new CachedInstance {
                    Instance = registration.CreateInstance(), LastCacheHit = DateTime.UtcNow
                };
                _cache.TryAdd(key, ci);
            }

            MaybeGroomCache();
            return(ci.Instance);
        }
예제 #6
0
 public object ActivateInstance(IObjectAssemblySpecification registration)
 {
     return(registration.CreateInstance());
 }