public TCompositeDeclaration ForExistingComposite <TCompositeDeclaration>(CompositeModelType compositeType) where TCompositeDeclaration : AbstractCompositeAssemblyDeclaration { var infos = this.GetInfosForAssemblingDeclaration(compositeType); return(this._assemblyScopeSupport[compositeType].CreateAssemblyDeclarationForExisting <TCompositeDeclaration>(this, infos.MQ.IQ)); }
public TCompositeDeclaration NewComposite <TCompositeDeclaration>(CompositeModelType compositeType) where TCompositeDeclaration : AbstractCompositeAssemblyDeclaration { var infos = this.GetInfosForAssemblingDeclaration(compositeType); return(this._assemblyScopeSupport[compositeType].CreateAssemblyDeclarationForNew <TCompositeDeclaration>(this, infos, this._assemblyScopeSupport[compositeType].CreateCompositeInfo(this._newCompositeIDRequestor(), this._parentContainer.Query), this._collectionsFactory)); }
public CompositeAssemblyInfoImpl(Int32 id, CompositeModelType modelType, UsesContainerQuery parentContainer) { ArgumentValidator.ValidateNotNull("Composite model type", modelType); this._id = id; this._fragmentInfos = new Dictionary <FragmentModelType, FragmentAssemblyInfo>(); this._defaultProviders = new Dictionary <PropertyInfo, Func <PropertyInfo, ApplicationSPI, Object> >(); this._metaInfoContainer = UsesContainerMutableImpl.CreateWithParent(parentContainer); this._modelType = modelType; this._types = new HashSet <Type>(); }
public IEnumerable <CompositeAssemblyInfo> GetInfos(CompositeModelType compositeType) { IEnumerable <CompositeAssemblyInfo> result = EMPTY_INFOS; DictionaryWithRoles <Type, ListProxy <CompositeAssemblyInfo>, ListProxyQuery <CompositeAssemblyInfo>, ListQuery <CompositeAssemblyInfo> > dic; if (this._compositeInfos.CQ.TryGetValue(compositeType, out dic)) { result = dic.CQ.Values.SelectMany(list => list.CQ); } return(result.Distinct(ReferenceEqualityComparer <CompositeAssemblyInfo> .ReferenceBasedComparer)); }
public AbstractCompositeAssemblyDeclarationForExistingImpl(Assembler assembler, CompositeModelType compositeModelType, DictionaryQuery <Type, ListQuery <CompositeAssemblyInfo> > compositeAssemblyInfos) { ArgumentValidator.ValidateNotNull("Assembler", assembler); ArgumentValidator.ValidateNotNull("Assembly infos", compositeAssemblyInfos); ArgumentValidator.ValidateNotNull("Composite model type", compositeModelType); this._assembler = assembler; this._compositeModelType = compositeModelType; this._composites = compositeAssemblyInfos; this._affectedTypes = new HashSet <Type>(); }
public CompositeModelInfo GetCompositeModelInfo(CompositeModelType modelType, IEnumerable <Type> compositeTypes) { ArgumentValidator.ValidateNotNull("Composite model type", modelType); ArgumentValidator.ValidateNotNull("Composite types", compositeTypes); CompositeModelInfo result = null; SetQuery <CompositeModelInfo> dic = null; if (this._compositeModels.TryGetValue(modelType, out dic)) { result = this.ResolveModelInfo(dic, compositeTypes); } return(result); }
public CompositeBuilder NewCompositeBuilder(CompositeModelType compositeModelType, IEnumerable <Type> compositeTypes) { ArgumentValidator.ValidateNotNull("Composite model type", compositeModelType); ArgumentValidator.ValidateNotNull("Composite types", compositeTypes); CompositeModelTypeInstanceScopeSupport support; if (this._modelSupport.TryGetValue(compositeModelType, out support)) { return(support.CreateBuilder(this, compositeTypes.ToArray())); } else { throw new InvalidCompositeModelTypeException(compositeModelType, "This application does not support this composite model type."); } }
public Boolean ForNewOrExistingComposite <TCompositeDeclaration>(CompositeModelType compositeType, IEnumerable <Type> types, out TCompositeDeclaration result) where TCompositeDeclaration : AbstractCompositeAssemblyDeclaration { var infos = this.GetInfosForAssemblingDeclaration(compositeType); var givenExceptExisting = types.Except(types.Where(typeInner => infos.CQ.Keys.Any(key => typeInner.GetGenericDefinitionIfContainsGenericParameters().IsAssignableFrom_IgnoreGenericArgumentsForGenericTypes(key)))); var returnValue = givenExceptExisting.Any(); if (returnValue) { // Completely new composite assembly declaration result = this.NewComposite <TCompositeDeclaration>(compositeType); } else { // There is already one or more existing infos result = this.ForExistingComposite <TCompositeDeclaration>(compositeType); } result.OfTypes(types.ToArray()); return(returnValue); }
public ServiceCompositeAssemblyInfoImpl(Int32 id, CompositeModelType modelType, UsesContainerQuery parent) : base(id, modelType, parent) { this._serviceID = null; this._activateWithApplication = false; }
public override CompositeBuilder CreateBuilder(StructureServiceProviderSPI structureServiceProvider, Type[] compositeTypes) { CompositeModelType mType = this.ModelScopeSupport.AssemblyScopeSupport.ModelType; throw new InvalidCompositeModelTypeException(mType, "Composite builders can not be used to create composites of type " + mType + "."); }
internal LayeredPlainCompositeAssemblyDeclarationForExistingImpl(Assembler assembler, CompositeModelType compositeModelType, DictionaryQuery <Type, ListQuery <CompositeAssemblyInfo> > compositeAssemblyInfos) : base(assembler, compositeModelType, compositeAssemblyInfos) { }
internal static CompositeBuilder CreateBuilder( CompositeModelTypeInstanceScopeSupport modelSupport, CompositeInstanceStructureOwner structureOwner, CompositeModelType compositeModelType, IEnumerable<Type> compositeTypes ) { var compositeTypesArr = compositeTypes.ToArray(); var tuple = ( (ModuleImpl) structureOwner ).FindModelForBuilder( compositeModelType, compositeTypesArr ); var uses = UsesContainerMutableImpl.CreateWithParent( tuple.Item2.UsesContainer ); return new CompositeBuilderImpl( compositeTypesArr, uses, (CompositeInstanceImpl) modelSupport.CreateInstance( tuple.Item1, tuple.Item2, compositeTypesArr, uses.Query ) ); }
internal Tuple<CompositeInstanceStructureOwner, CompositeModel> FindModelForBuilder( CompositeModelType compositeModelType, Type[] compositeTypes ) { // TODO might get rid of tuple? if lookup is done by target module #if SILVERLIGHT IDictionary<Type[], Tuple<CompositeInstanceStructureOwner, CompositeModel>> cache; lock ( this._compositeTypeLookupCache ) { cache = this._compositeTypeLookupCache.GetOrAdd_NotThreadSafe( compositeModelType, key => new Dictionary<Type[], Tuple<CompositeInstanceStructureOwner, CompositeModel>>( ArrayEqualityComparer<Type>.DefaultArrayEqualityComparer ) ); #else var cache = this._compositeTypeLookupCache.GetOrAdd( compositeModelType, key => new System.Collections.Concurrent.ConcurrentDictionary<Type[], Tuple<CompositeInstanceStructureOwner, CompositeModel>>( ArrayEqualityComparer<Type>.DefaultArrayEqualityComparer ) ); #endif #if SILVERLIGHT } #endif #if SILVERLIGHT lock ( cache ) { #endif return cache. #if SILVERLIGHT GetOrAdd_NotThreadSafe( #else GetOrAdd( #endif compositeTypes, ( compositeTypez ) => // lambda will need composite model type -> can't fully optimize { var models = this.FindVisibleModels( compositeModel => compositeModel.ModelType.Equals( compositeModelType ) && compositeTypes.All( cType => compositeModel.PublicTypes.Any( pType => cType.GetGenericDefinitionIfGenericType().IsAssignableFrom_IgnoreGenericArgumentsForGenericTypes( pType ) ) ) ); var array = models.Take( 2 ).ToArray(); if ( array.Length > 1 ) { // This can happen when same layer is reachable via two other layers, e.g. // A // / \ // B C // \ / // D // If one makes search from module A for composite type present in module D in one composite model, one will get two references to same composite model in D array = models.Distinct().Take( 2 ).ToArray(); } if ( array.Length == 0 ) { throw new NoSuchCompositeTypeException( compositeTypes ); } else { if ( array.Length > 1 ) { throw new AmbiguousTypeException( compositeTypes, models.Select( tuple => tuple.Item2.PublicTypes ) ); } else { // Try to search for model info. If the composite type is ambiguous in the scope of that module, the exception will be thrown. //( (ModuleInstance) result.Item1 ).ModelInfoContainer.GetCompositeModelInfo( compositeModelType, compositeType ); return array[0]; } } } ); #if SILVERLIGHT } #endif }
internal LayeredCompositeAssemblyInfoImpl(Int32 id, CompositeModelType modelType, UsesContainerQuery parentContainer) : base(id, modelType, parentContainer) { this._visibility = DEFAULT_VISIBILITY; }
protected DictionaryWithRoles <Type, ListProxy <CompositeAssemblyInfo>, ListProxyQuery <CompositeAssemblyInfo>, ListQuery <CompositeAssemblyInfo> > GetInfosForAssemblingDeclaration(CompositeModelType compositeModelType) { ArgumentValidator.ValidateNotNull("Composite model type", compositeModelType); DictionaryWithRoles <Type, ListProxy <CompositeAssemblyInfo>, ListProxyQuery <CompositeAssemblyInfo>, ListQuery <CompositeAssemblyInfo> > infos; if (!this._compositeInfos.CQ.TryGetValue(compositeModelType, out infos)) { infos = this._collectionsFactory.NewDictionary <Type, ListProxy <CompositeAssemblyInfo>, ListProxyQuery <CompositeAssemblyInfo>, ListQuery <CompositeAssemblyInfo> >(); this._compositeInfos.Add(compositeModelType, infos); } return(infos); }
/// <summary> /// Shortcut method to create a composite of specified <see cref="CompositeModelType"/> without further setting up of <see cref="CompositeBuilder"/>. /// </summary> /// <typeparam name="TComposite">The type of the composite.</typeparam> /// <param name="ssp">The <see cref="StructureServiceProvider"/>.</param> /// <param name="compositeModelType">The <see cref="CompositeModelType"/> of the composite.</param> /// <returns>A new instance of composite with given <see cref="CompositeModelType"/>.</returns> /// <exception cref="NullReferenceException">If <paramref name="ssp"/> is <c>null</c>.</exception> /// <remarks> /// See <see cref="StructureServiceProvider.NewCompositeBuilder(CompositeModelType, IEnumerable{Type})"/> and <see cref="CompositeBuilder.InstantiateWithType(Type)"/> methods for more exception scenarios. /// </remarks> /// <seealso cref="StructureServiceProvider.NewCompositeBuilder(CompositeModelType, IEnumerable{Type})"/> /// <seealso cref="CompositeBuilder.InstantiateWithType(Type)"/> public static TComposite NewComposite <TComposite>(this StructureServiceProvider ssp, CompositeModelType compositeModelType) { return(ssp.NewCompositeBuilder <TComposite>(compositeModelType).Instantiate()); }
/// <summary> /// Helper method to create new composite builder with specified <see cref="CompositeModelType"/> and only one type, known at compile time, to be used as search criteria. /// </summary> /// <typeparam name="TComposite">The type of the composite, to be used as search criterion when searching for suitable composite model.</typeparam> /// <param name="ssp">The <see cref="StructureServiceProvider"/></param> /// <param name="compositeModelType">The <see cref="CompositeModelType"/> to be used when searching for suitable composite model.</param> /// <returns>A new <see cref="CompositeBuilderInfo{T}"/> instance matching the search criteria.</returns> /// <exception cref="NullReferenceException">If <paramref name="ssp"/> is <c>null</c>.</exception> /// <remarks> /// See <see cref="StructureServiceProvider.NewCompositeBuilder(CompositeModelType, IEnumerable{Type})"/> method for more exception scenarios. /// </remarks> /// <seealso cref="StructureServiceProvider.NewCompositeBuilder(CompositeModelType, IEnumerable{Type})"/> /// <seealso cref="CompositeBuilderInfo{T}"/> public static CompositeBuilderInfo <TComposite> NewCompositeBuilder <TComposite>(this StructureServiceProvider ssp, CompositeModelType compositeModelType) { return(new CompositeBuilderInfo <TComposite>(ssp.NewCompositeBuilder(compositeModelType, typeof(TComposite).Singleton()))); }
/// <summary> /// Helper method to create new composite builder with specified <see cref="CompositeModelType"/> and only one type to be used as search criteria. /// </summary> /// <param name="ssp">The <see cref="StructureServiceProvider"/>.</param> /// <param name="compositeModelType">The <see cref="CompositeModelType"/> to be used when searching for suitable composite model.</param> /// <param name="compositeType">The type of the composite, to be used as search criterion when searching for suitable composite model.</param> /// <returns>A new <see cref="CompositeBuilder"/> instance matching the search criteria.</returns> /// <exception cref="NullReferenceException">If <paramref name="ssp"/> is <c>null</c>.</exception> /// <remarks> /// See <see cref="StructureServiceProvider.NewCompositeBuilder(CompositeModelType, IEnumerable{Type})"/> method for more exception scenarios. /// </remarks> /// <seealso cref="StructureServiceProvider.NewCompositeBuilder(CompositeModelType, IEnumerable{Type})"/> public static CompositeBuilder NewCompositeBuilder(this StructureServiceProvider ssp, CompositeModelType compositeModelType, Type compositeType) { return(ssp.NewCompositeBuilder(compositeModelType, compositeType.Singleton())); }
public ServiceCompositeAssemblyDeclarationForExistingImpl(Assembler assembler, CompositeModelType compositeModelType, DictionaryQuery <Type, ListQuery <CompositeAssemblyInfo> > compositeAssemblyInfos) : base(assembler, compositeModelType, compositeAssemblyInfos) { }