public StructureServiceProviderImpl( CompositeInstanceStructureOwner structure, DictionaryQuery <CompositeModelType, CompositeModelTypeInstanceScopeSupport> modelSupport, Func <Func <CompositeModel, Boolean>, IEnumerable <Tuple <CompositeInstanceStructureOwner, CompositeModel> > > serviceFinderFunction ) { ArgumentValidator.ValidateNotNull("Structure", structure); ArgumentValidator.ValidateNotNull("Model type support", modelSupport); ArgumentValidator.ValidateNotNull("Service finder function", serviceFinderFunction); this._structure = structure; this._modelSupport = modelSupport; this._modelFinder = serviceFinderFunction; }
internal ServiceCompositeInstanceImpl(CompositeInstanceStructureOwner structureOwner, CompositeModel model, IEnumerable <Type> publicCompositeType, UsesContainerQuery usesContainer, String serviceID, MainCompositeConstructorArguments mainCtorArgs) : base(structureOwner, model, publicCompositeType, usesContainer, mainCtorArgs) { var publicCtors = mainCtorArgs.Arguments; this._activationState = (Int32)ActivationState.PASSIVE; this._activationInProgress = null; this._activationAction = (Action)publicCtors[COMPOSITE_CTOR_FIRST_ADDITIONAL_PARAM_IDX + COMPOSITE_CTOR_ADDITIONAL_PARAMS_COUNT]; this._passivationInProgress = null; this._passivationAction = (Action)publicCtors[COMPOSITE_CTOR_FIRST_ADDITIONAL_PARAM_IDX + COMPOSITE_CTOR_ADDITIONAL_PARAMS_COUNT + 1]; this._serviceID = serviceID; this._activatingAllowed = (Int32)ActivatingAllowed.ALLOWED; this._needToSetIdentity = Convert.ToInt32(true); }
public ServiceCompositeInstance GetService(CompositeInstanceStructureOwner structureOwner, CompositeModel model, IEnumerable <Type> serviceTypes, UsesContainerQuery usesContainer, String serviceID) { #if SILVERLIGHT lock (this._services) { #endif return(this._services. #if SILVERLIGHT GetOrAdd_NotThreadSafe( #else GetOrAdd( #endif serviceID, id => { var builderUses = UsesContainerMutableImpl.CreateWithParent(model.UsesContainer); var instance = new ServiceCompositeInstanceImpl(structureOwner, model, serviceTypes, builderUses.Query, serviceID, new MainCompositeConstructorArguments()); return instance; })); #if SILVERLIGHT } #endif }
public virtual CompositeInstance CreateInstance(CompositeInstanceStructureOwner structureOwner, CompositeModel model, IEnumerable <Type> publicCompositeTypes, UsesContainerQuery usesContainer) { return(new CompositeInstanceImpl(structureOwner, model, publicCompositeTypes, usesContainer)); }
protected abstract ServiceContainer GetServiceContainerFor(CompositeInstanceStructureOwner structureOwner);
protected abstract IEnumerable <CompositeModel> GetAllModels(CompositeInstanceStructureOwner structureOwner, Boolean isActivation);
public override CompositeInstance CreateInstance(CompositeInstanceStructureOwner structureOwner, CompositeModel model, IEnumerable <Type> publicCompositeTypes, UsesContainerQuery usesContainer) { return(this .GetServiceContainerFor(structureOwner) .GetService(structureOwner, model, publicCompositeTypes, usesContainer, ((ServiceCompositeModel)model).ServiceID)); }
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 static ServiceContainer GetServiceContainerFor( CompositeInstanceStructureOwner structureOwner ) { return ( (ModuleImpl) structureOwner )._serviceContainer; }
protected CompositeInstanceImpl( CompositeInstanceStructureOwner structureOwner, CompositeModel model, IEnumerable <Type> publicCompositeTypes, UsesContainerQuery usesContainer, MainCompositeConstructorArguments publicCtorArgsObject ) { ArgumentValidator.ValidateNotNull("Structure owner", structureOwner); ArgumentValidator.ValidateNotNull("Composite model", model); ArgumentValidator.ValidateNotEmpty("Composite type", publicCompositeTypes); ArgumentValidator.ValidateNotNull("Container for objects to be used in fragment creation", usesContainer); this._structureOwner = structureOwner; var application = this._structureOwner.Application; this._modelInfo = this._structureOwner.ModelInfoContainer.GetCompositeModelInfo(model); if (publicCompositeTypes.Any(pcType => pcType.ContainsGenericParameters())) { throw new InternalException("With given public composite types {" + String.Join(", ", publicCompositeTypes) + "} and public composite type in model being [" + String.Join(", ", model.PublicTypes) + "], the public composite types contained non-closed generic parameters."); } this._usesContainer = usesContainer; this._isPrototype = (Int32)PrototypeState.PROTOTYPE; this._invocationInfos = new Lazy <ThreadLocal <Stack <InvocationInfo> > >(() => new ThreadLocal <Stack <InvocationInfo> >(() => new Stack <InvocationInfo>()), LazyThreadSafetyMode.PublicationOnly); var composites = application.CollectionsFactory.NewDictionaryProxy <Type, Object>(); var cProps = application.CollectionsFactory.NewListProxy(new List <CompositeProperty>(model.Methods.Count * 2)); var cEvents = application.CollectionsFactory.NewListProxy(new List <CompositeEvent>(model.Methods.Count * 2)); var publicTypeGenResult = this._modelInfo.Types; var factory = publicTypeGenResult.CompositeFactory; var gArgs = publicTypeGenResult.PublicCompositeGenericArguments.Count == 0 ? null : new Type[publicTypeGenResult.GeneratedMainPublicType.GetGenericArguments().Length]; this._gArgs = gArgs; foreach (var pType in publicCompositeTypes) { ListQuery <Int32> gArgInfo = null; if (publicTypeGenResult.PublicCompositeGenericArguments.TryGetValue(pType.GetGenericDefinitionIfGenericType(), out gArgInfo)) { var declaredGArgs = pType.GetGenericArguments(); for (Int32 i = 0; i < declaredGArgs.Length; ++i) { gArgs[gArgInfo[i]] = declaredGArgs[i]; } } } if (gArgs != null && gArgs.Any(gArg => gArg == null)) { throw new InvalidCompositeTypeException(publicCompositeTypes, "Could not find suitable generic argument for all public types of composite " + this._modelInfo.Model + "."); } Action prePrototypeAction = null; var publicCtorArgs = new Object[publicTypeGenResult.MaxParamCountForCtors]; Object[] compositeCtorParams = null; foreach (var genType in publicTypeGenResult.GeneratedPublicTypes) { var isMainType = genType.GeneratedType.Equals(this._modelInfo.Types.GeneratedMainPublicType); var curCtorArgs = isMainType ? publicCtorArgs : compositeCtorParams; this.SetCompositeCtorArgs(ref curCtorArgs, cProps.AO, cEvents.AO); var publicComposite = factory.CreateInstance(genType.GeneratedTypeID, gArgs, curCtorArgs); foreach (var cType in this.GetTypeKeysForGeneratedType(publicComposite.GetType(), true, isMainType)) { composites[cType] = publicComposite; } if (isMainType) { if (publicCtorArgsObject != null) { publicCtorArgsObject.Arguments = curCtorArgs; } prePrototypeAction = (Action)publicCtorArgs[COMPOSITE_CTOR_FIRST_ADDITIONAL_PARAM_IDX]; this._prototypeAction = (Action)publicCtorArgs[COMPOSITE_CTOR_FIRST_ADDITIONAL_PARAM_IDX + 1]; this._checkStateFunc = (Action <IDictionary <QualifiedName, IList <ConstraintViolationInfo> > >)publicCtorArgs[COMPOSITE_CTOR_FIRST_ADDITIONAL_PARAM_IDX + 2]; this._compositeMethods = new Lazy <MethodInfo[]>(() => ((CompositeCallbacks)publicComposite).GetCompositeMethods(), LazyThreadSafetyMode.ExecutionAndPublication); } } this._isPrototypeTransitionInProgress = null; this.SetCompositeCtorArgs(ref compositeCtorParams, cProps.AO, cEvents.AO); foreach (var typeGenResult in publicTypeGenResult.PrivateCompositeGenerationResults) { var privateComposite = factory.CreateInstance(typeGenResult.GeneratedTypeID, gArgs, compositeCtorParams); foreach (var cTypeOrParent in this.GetTypeKeysForGeneratedType(privateComposite.GetType(), false, false)) { composites.Add(cTypeOrParent, privateComposite); } } this._composites = composites.CQ; this._methodsToModels = new Lazy <DictionaryQuery <MethodInfo, CompositeMethodModel> >(() => { var retVal = new Dictionary <MethodInfo, CompositeMethodModel>(); var cMethods = this._compositeMethods.Value; for (var i = 0; i < cMethods.Length; ++i) { var cm = cMethods[i]; retVal.Add(cm, this._modelInfo.Model.Methods[i]); } return(application.CollectionsFactory.NewDictionaryProxy(retVal).CQ); }, LazyThreadSafetyMode.ExecutionAndPublication); this._state = new CompositeStateImpl(this._structureOwner.Application.CollectionsFactory, cProps.CQ, cEvents.CQ); this._fragmentInstancePools = this.CreatePoolDictionary <FragmentTypeGenerationResult, FragmentInstance>( gArgs, this._modelInfo.Types.FragmentGenerationResults.Where(fGenResult => fGenResult.InstancePoolRequired), application.CollectionsFactory); var fInstances = application.CollectionsFactory.NewDictionaryProxy(new Dictionary <Type, FragmentInstance>()); foreach (var genResult in publicTypeGenResult.FragmentGenerationResults.Where(val => !val.InstancePoolRequired)) { var genType = genResult.GeneratedType; if (gArgs != null) { genType = genType.MakeGenericType(gArgs); } else if (genType.ContainsGenericParameters()) { throw new InternalException("Could not find generic arguments for fragment type " + genResult.DeclaredType + "."); } fInstances.Add(genType, new FragmentInstanceImpl()); } this._fragmentInstances = fInstances.CQ; this._concernInvocationInstances = this.CreatePoolDictionary <TypeGenerationResult, FragmentDependant>(gArgs, publicTypeGenResult.ConcernInvocationGenerationResults, application.CollectionsFactory); this._sideEffectInvocationInstances = this.CreatePoolDictionary <TypeGenerationResult, FragmentDependant>(gArgs, publicTypeGenResult.SideEffectGenerationResults, application.CollectionsFactory); this._constructorsForFragments = application.CollectionsFactory.NewDictionaryProxy <Type, ListQuery <FragmentConstructorInfo> >(this._fragmentInstancePools.Keys.Concat(this._fragmentInstances.Keys) .ToDictionary( fType => fType, fType => application.CollectionsFactory.NewListProxy(fType .GetAllInstanceConstructors() .Select(fCtor => { Int32 idx; return(fCtor.TryGetConstructorModelIndex(out idx) ? new FragmentConstructorInfo(model.Constructors[idx], fCtor) : null); }) .Where(i => i != null) .ToList() ).CQ )).CQ; if (prePrototypeAction != null) { prePrototypeAction(); } }
public CompositeInstanceImpl(CompositeInstanceStructureOwner structureOwner, CompositeModel model, IEnumerable <Type> publicCompositeTypes, UsesContainerQuery usesContainer) : this(structureOwner, model, publicCompositeTypes, usesContainer, null) { }
internal static ServiceContainer GetServiceContainer(CompositeInstanceStructureOwner structureOwner) { return(((SingletonApplicationImpl)structureOwner)._serviceContainer); }
protected override IEnumerable <CompositeModel> GetAllModels(CompositeInstanceStructureOwner structureOwner, Boolean isActivation) { return(((Module)structureOwner).ModuleModel.CompositeModelsInThisContainer); }
protected override ServiceContainer GetServiceContainerFor(CompositeInstanceStructureOwner structureOwner) { return(ModuleImpl.GetServiceContainerFor(structureOwner)); }
protected override IEnumerable <CompositeModel> GetAllModels(CompositeInstanceStructureOwner structureOwner, Boolean isActivation) { return(structureOwner.Application.ApplicationModel.CompositeModels.Values); }
protected override ServiceContainer GetServiceContainerFor(CompositeInstanceStructureOwner structureOwner) { return(SingletonApplicationImpl.GetServiceContainer(structureOwner)); }