public void SingletonProviderReturnsInstance() { SingletonProvider singletonProvider = new SingletonProvider(typeof(Clazz), injector); object returnedResponse = singletonProvider.Apply(null, injector, null); Assert.IsInstanceOf <Clazz>(returnedResponse); }
public void usingDestroyedSingletonProviderThrows() { SingletonProvider provider = new SingletonProvider(typeof(Clazz), injector); provider.Destroy(); provider.Apply(null, injector, null); }
public IContent GetSingleton(string id) { var contentType = ContentTypeProvider.Get(id); var singleton = SingletonProvider.Get(id); return(ContainerSpecificContentGetter.Get <IContent>(singleton.Id, null, contentType.Container)); }
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); }
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); }
/// <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); }
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()); }
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); }
/// <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); }