示例#1
0
        public void SingletonProviderReturnsInstance()
        {
            SingletonProvider singletonProvider = new SingletonProvider(typeof(Clazz), injector);
            object            returnedResponse  = singletonProvider.Apply(null, injector, null);

            Assert.IsInstanceOf <Clazz>(returnedResponse);
        }
示例#2
0
        public void usingDestroyedSingletonProviderThrows()
        {
            SingletonProvider provider = new SingletonProvider(typeof(Clazz), injector);

            provider.Destroy();
            provider.Apply(null, injector, null);
        }
示例#3
0
        public IContent GetSingleton(string id)
        {
            var contentType = ContentTypeProvider.Get(id);

            var singleton = SingletonProvider.Get(id);

            return(ContainerSpecificContentGetter.Get <IContent>(singleton.Id, null, contentType.Container));
        }
示例#4
0
        public void DestroyingSingletonProviderInvokesPreDestroyMethodsOnSingleton()
        {
            SingletonProvider provider  = new SingletonProvider(typeof(Clazz), injector);
            Clazz             singleton = provider.Apply(null, injector, null) as Clazz;

            provider.Destroy();
            Assert.True(singleton.preDestroyCalled);
        }
示例#5
0
        public void SameSingletonIsReturnedOnSecondResponse()
        {
            SingletonProvider singletonProvider = new SingletonProvider(typeof(Clazz), injector);
            object            returnedResponse  = singletonProvider.Apply(null, injector, null);
            object            secondResponse    = singletonProvider.Apply(null, injector, null);

            Assert.AreEqual(returnedResponse, secondResponse);
        }
示例#6
0
文件: Property.cs 项目: pkim/Hlib
        /// <summary>
        /// deserilaize the property
        /// </summary>
        public void Deserialize()
        {
            TPropertyType propertyType = instance;

            if (XMLHandler.TryDeserialize(ref propertyType, this.FilePath))
            {
                SingletonProvider.SetInstance(instance);
            }
        }
        public void SetProviderChangesTheProvider()
        {
            SingletonProvider provider1 = new SingletonProvider(typeof(Clazz), injector);
            TypeProvider      provider2 = new TypeProvider(typeof(Clazz));
            InjectionMapping  config    = new InjectionMapping(injector, new MappingId(typeof(Clazz), null));

            config.ToProvider(provider1);
            Assert.AreEqual(config.GetProvider(), provider1);
            config.ToProvider(null);
            config.ToProvider(provider2);
            Assert.AreEqual(config.GetProvider(), provider2);
        }
示例#8
0
        public IEnumerable <ContentTypeResponseItem> GetContentTypes()
        {
            var result = new List <ContentTypeResponseItem>();

            foreach (var contentType in ContentTypeProvider.GetAll())
            {
                var    name = contentType.Type.GetCustomAttribute <DisplayAttribute>()?.Name ?? contentType.Type.Name;
                string pluralName;

                if (name.Contains(':') && !contentType.Id.Contains(':'))
                {
                    var nameSplit = name.Split(':');

                    name       = nameSplit.First();
                    pluralName = nameSplit.Last();
                }
                else
                {
                    name       = Humanizer.Humanize(name);
                    pluralName = Pluralizer.Pluralize(name);
                }

                var singleton = SingletonProvider.Get(contentType.Id);

                result.Add(new ContentTypeResponseItem
                {
                    Id                       = contentType.Id,
                    Name                     = name,
                    PluralName               = pluralName,
                    IsNameable               = typeof(INameable).IsAssignableFrom(contentType.Type),
                    NameablePropertyName     = typeof(INameable).IsAssignableFrom(contentType.Type) ? CamelCaseNamingStrategy.GetPropertyName(NameExpressionParser.Parse(contentType.Type), false) : null,
                    IsRoutable               = typeof(IRoutable).IsAssignableFrom(contentType.Type),
                    IsSingleton              = singleton != null,
                    Count                    = -1,
                    ContentTypeActionModules = ContentTypeActionModuleProvider.GetContentTypeActionModulesFor(contentType.Id),
                    ListActionModules        = ListActionModuleProvider.GetListActionModulesFor(contentType.Id),
                });
            }

            return(result.AsReadOnly());
        }
示例#9
0
        ContentTypeResponseItem GetItem(ContentTypeDescriptor contentType)
        {
            var    name = contentType.Type.GetCustomAttribute <DisplayAttribute>()?.Name ?? contentType.Type.Name;
            string pluralName;

            if (name.Contains(':') && !contentType.Id.Contains(':'))
            {
                var nameSplit = name.Split(':');

                name       = nameSplit.First();
                pluralName = nameSplit.Last();
            }
            else
            {
                name       = Humanizer.Humanize(name);
                pluralName = Pluralizer.Pluralize(name);
            }

            var singleton = SingletonProvider.Get(contentType.Id);

            var item = new ContentTypeResponseItem
            {
                Id                       = contentType.Id,
                Name                     = name,
                LowerCaseName            = name.Substring(0, 1).ToLower() + name.Substring(1),
                PluralName               = pluralName,
                LowerCasePluralName      = pluralName.Substring(0, 1).ToLower() + pluralName.Substring(1),
                IsNameable               = typeof(INameable).IsAssignableFrom(contentType.Type),
                NameablePropertyName     = typeof(INameable).IsAssignableFrom(contentType.Type) ? CamelCaseNamingStrategy.GetPropertyName(NameExpressionParser.Parse(contentType.Type), false) : null,
                IsImageable              = typeof(IImageable).IsAssignableFrom(contentType.Type),
                ImageablePropertyName    = typeof(IImageable).IsAssignableFrom(contentType.Type) ? CamelCaseNamingStrategy.GetPropertyName(ImageExpressionParser.Parse(contentType.Type), false) : null,
                IsRoutable               = typeof(IRoutable).IsAssignableFrom(contentType.Type),
                IsSingleton              = singleton != null,
                Count                    = -1,
                ContentTypeActionModules = ContentTypeActionModuleProvider.GetContentTypeActionModulesFor(contentType.Id),
                ListActionModules        = ListActionModuleProvider.GetListActionModulesFor(contentType.Id),
                ContentTypeGroups        = ContentTypeGroupMatcher.GetContentTypeGroupsFor(contentType.Id).Select(t => t.Id).ToList().AsReadOnly(),
            };

            return(item);
        }
示例#10
0
文件: Property.cs 项目: pkim/Hlib
        /// <summary>
        /// Initializes a new property instance as singelton
        /// and de/serializes ist.
        /// </summary>
        /// <returns>the de/serialized property instance</returns>
        private static TPropertyType GetInstance(out Boolean _new)
        {
            // get the instance of the property as singelton
            Property <TPropertyType> .instance = SingletonProvider.GetInstance <TPropertyType>(out _new);

            // if the instance is not already serialized
            // serialize it
            if (!System.IO.File.Exists(instance.FilePath) && Property <TPropertyType> .instance.Serializeable)
            {
                Property <TPropertyType> .instance.Serialize();
            }

            // If the instance is new initialized
            // deserialize it
            else if (_new && Property <TPropertyType> .instance.Deserializeable)
            {
                Property <TPropertyType> .instance.Deserialize();
            }

            // return the de/serialized instance
            return(Property <TPropertyType> .instance);
        }