예제 #1
0
        public bool Has(Type pluginType, Instance instance)
        {
            var    key = instance.InstanceKey(pluginType);
            object @object;

            return(_objects.TryGetValue(key, out @object));
        }
예제 #2
0
        public object Get(Type pluginType, Instance instance, IBuildSession session)
        {
            object result = null;
            int key = instance.InstanceKey(pluginType);
            _lock.EnterUpgradeableReadLock();
            if (_objects.ContainsKey(key))
            {

                result = _objects[key];
                _lock.ExitUpgradeableReadLock();
            }
            else
            {
                _lock.EnterWriteLock();
                try
                {
                    result = buildWithSession(pluginType, instance, session);
                    _objects.Add(key, result);
                }
                finally
                {
                    _lock.ExitWriteLock();
                }
            }

            return result;
        }
예제 #3
0
        public object Get(Type pluginType, Instance instance, IBuildSession session)
        {
            object result;
            var    key = instance.InstanceKey(pluginType);

            _lock.EnterUpgradeableReadLock();
            try
            {
                if (_objects.ContainsKey(key))
                {
                    result = _objects[key];
                }
                else
                {
                    _lock.EnterWriteLock();
                    try
                    {
                        result = buildWithSession(pluginType, instance, session);
                        _objects.Add(key, result);
                    }
                    finally
                    {
                        _lock.ExitWriteLock();
                    }
                }
            }
            finally
            {
                _lock.ExitUpgradeableReadLock();
            }

            return(result);
        }
예제 #4
0
 public bool Has(Type pluginType, Instance instance)
 {
     return(_lock.Read(() => {
         var key = instance.InstanceKey(pluginType);
         return _objects.ContainsKey(key);
     }));
 }
예제 #5
0
 public bool Has(Type pluginType, Instance instance)
 {
     return _lock.Read(() => {
         var key = instance.InstanceKey(pluginType);
         return _objects.ContainsKey(key);
     });
 }
예제 #6
0
        public void Set(Type pluginType, Instance instance, object value)
        {
            if (value == null)
            {
                return;
            }

            var key = instance.InstanceKey(pluginType);

            _objects.AddOrUpdate(key, value, (_, __) => value);
        }
예제 #7
0
        public void Eject(Type pluginType, Instance instance)
        {
            int key = instance.InstanceKey(pluginType);
            _lock.MaybeWrite(() => {
                if (!_objects.ContainsKey(key)) return;

                _lock.Write(() => {
                    var disposable = _objects[key] as IDisposable;
                    _objects.Remove(key);
                    disposable.SafeDispose();
                });
            });
        }
예제 #8
0
        public void Eject(Type pluginType, Instance instance)
        {
            var key = instance.InstanceKey(pluginType);

            _lock.MaybeWrite(() => {
                if (!_objects.ContainsKey(key))
                {
                    return;
                }

                _lock.Write(() => {
                    var disposable = _objects[key] as IDisposable;
                    _objects.Remove(key);
                    disposable.SafeDispose();
                });
            });
        }
예제 #9
0
        public void Eject(Type pluginType, Instance instance)
        {
            // Prevent null reference exception.
            if (pluginType.AssemblyQualifiedName == null)
            {
                return;
            }

            var key = instance.InstanceKey(pluginType);

            object @object;

            if (_objects.TryRemove(key, out @object))
            {
                @object.SafeDispose();
            }
        }
예제 #10
0
        public void Eject(Type pluginType, Instance instance)
        {
            // Prevent null reference exception.
            if (pluginType.AssemblyQualifiedName == null)
                return;

            var key = instance.InstanceKey(pluginType);
            _lock.MaybeWrite(() => {
                if (!_objects.ContainsKey(key)) return;

                _lock.Write(() => {
                    var disposable = _objects[key] as IDisposable;
                    _objects.Remove(key);
                    disposable.SafeDispose();
                });
            });
        }
예제 #11
0
        public void Set(Type pluginType, Instance instance, object value)
        {
            if (value == null)
            {
                return;
            }

            _lock.Write(() => {
                var key = instance.InstanceKey(pluginType);
                if (_objects.ContainsKey(key))
                {
                    _objects[key] = value;
                }
                else
                {
                    _objects.Add(key, value);
                }
            });
        }
예제 #12
0
        public object Get(Type pluginType, Instance instance, IBuildSession session)
        {
            object result;
            var    key = instance.InstanceKey(pluginType);

            _lock.EnterUpgradeableReadLock();
            try
            {
                if (_instances.Contains(instance))
                {
                    throw new StructureMapBuildException("Bi-directional dependency relationship detected!" +
                                                         Environment.NewLine + "Check the StructureMap stacktrace below:");
                }

                if (_objects.ContainsKey(key))
                {
                    result = _objects[key];
                }
                else
                {
                    _lock.EnterWriteLock();
                    try
                    {
                        _instances.Add(instance);
                        result = buildWithSession(pluginType, instance, session);

                        _objects.Add(key, result);
                    }
                    finally
                    {
                        _instances.Remove(instance);
                        _lock.ExitWriteLock();
                    }
                }
            }
            finally
            {
                _lock.ExitUpgradeableReadLock();
            }

            return(result);
        }
예제 #13
0
        public object Get(Type pluginType, Instance instance, IBuildSession session)
        {
            object result;
            var key = instance.InstanceKey(pluginType);
            _lock.EnterUpgradeableReadLock();
            try
            {
                if (_instances.Contains(instance))
                {
                    throw new StructureMapBuildException("Bi-directional dependency relationship detected!" +
                                                         Environment.NewLine + "Check the StructureMap stacktrace below:");
                }

                if (_objects.ContainsKey(key))
                {
                    result = _objects[key];
                }
                else
                {
                    _lock.EnterWriteLock();
                    try
                    {
                        _instances.Add(instance);
                        result = buildWithSession(pluginType, instance, session);

                        _objects.Add(key, result);
                    }
                    finally
                    {
                        _instances.Remove(instance);
                        _lock.ExitWriteLock();
                    }
                }
            }
            finally
            {
                _lock.ExitUpgradeableReadLock();
            }

            return result;
        }
예제 #14
0
        public void Eject(Type pluginType, Instance instance)
        {
            // Prevent null reference exception.
            if (pluginType.AssemblyQualifiedName == null)
            {
                return;
            }

            var key = instance.InstanceKey(pluginType);

            _lock.MaybeWrite(() => {
                if (!_objects.ContainsKey(key))
                {
                    return;
                }

                _lock.Write(() => {
                    var disposable = _objects[key] as IDisposable;
                    _objects.Remove(key);
                    disposable.SafeDispose();
                });
            });
        }
예제 #15
0
        public void Set(Type pluginType, Instance instance, object value)
        {
            if (value == null) return;

            _lock.Write(() => {
                int key = instance.InstanceKey(pluginType);
                if (_objects.ContainsKey(key))
                {
                    _objects[key] = value;
                }
                else
                {
                    _objects.Add(key, value);
                }
            });
        }
예제 #16
0
        public object Get(Type pluginType, Instance instance, IBuildSession session)
        {
            var key = instance.InstanceKey(pluginType);

            return(_objects.GetOrAdd(key, _ => buildWithSession(pluginType, instance, session)));
        }