public T GetNotifierStrategy <T>(params object[] objects)
            where T : class, INotifierStrategy
        {
            var validationName = typeof(T).FullName;

            var validationInstance = default(T);

            if (_cacheComponent.ContainsKey(validationName))
            {
                validationInstance = _cacheComponent.TryGetValue <T>(validationName);
            }
            else
            {
                try
                {
                    if (_mutex.WaitOne())
                    {
                        var constructorInfo = typeof(T).GetConstructor(objects.Select(objectInstance => objectInstance.GetType()).ToArray());
                        if (constructorInfo != null)
                        {
                            validationInstance = (T)constructorInfo.Invoke(objects);

                            if (!_cacheComponent.ContainsKey(validationName))
                            {
                                _cacheComponent.TryAdd(validationName, validationInstance);
                            }
                        }
                    }
                }
                finally
                {
                    _mutex.ReleaseMutex();
                }
            }

            return(validationInstance);
        }
Beispiel #2
0
        public T GetValidationSpec <T, TParam>() where T : class, ISpecification <TParam>
        {
            var validationName = typeof(T).FullName;

            var validationInstance = default(T);

            if (_cacheComponent.ContainsKey(validationName))
            {
                validationInstance = _cacheComponent.TryGetValue <T>(validationName);
            }
            else
            {
                try
                {
                    if (_mutex.WaitOne())
                    {
                        var constructorInfo = typeof(T).GetConstructor(Type.EmptyTypes);
                        if (constructorInfo != null)
                        {
                            validationInstance = (T)constructorInfo.Invoke(null);

                            if (!_cacheComponent.ContainsKey(validationName))
                            {
                                _cacheComponent.TryAdd(validationName, validationInstance);
                            }
                        }
                    }
                }
                finally
                {
                    _mutex.ReleaseMutex();
                }
            }

            return(validationInstance);
        }
        public T GetComponent <T>() where T : class
        {
            var name = typeof(T).FullName;

            if (_cacheComponent.ContainsKey(name))
            {
                return(_cacheComponent.TryGetValue <T>(name));
            }

            var component = CreateComponentByAbstractFactory <T>();

            if (component != null)
            {
                _cacheComponent.TryAdd(name, component);
            }

            return(component);
        }