private object GetOrCreateInstance(ConfiguratedType configuratedType)
        {
            if (configuratedType != null)
            {
                if (configuratedType.IsSingleton)
                {
                    if (configuratedType.Instance == null)
                    {
                        lock (syncRoot)
                        {
                            if (configuratedType.Instance == null)
                            {
                                configuratedType.Instance = Create(configuratedType.ImplementationInterface);
                            }
                        }
                    }
                    return(configuratedType.Instance);
                }

                return(Create(configuratedType.ImplementationInterface));
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
        public void RegisterType(Type TInterface, Type TImplementation, bool isSingleton = false)
        {
            if (!TImplementation.IsInterface && !TImplementation.IsAbstract && TInterface.IsAssignableFrom(TImplementation))
            {
                ConfiguratedType configuratedType = new ConfiguratedType(TInterface, TImplementation, isSingleton);

                if (_configuration.ContainsKey(TInterface))
                {
                    _configuration[TInterface].Add(configuratedType);
                }
                else
                {
                    _configuration.Add(TInterface, new List <ConfiguratedType> {
                        configuratedType
                    });
                }
            }
            else
            {
                throw new Exception($"{TImplementation.ToString()} can't be added with {TInterface.ToString()}");
            }
        }