public override void ApplicationPassivating(ApplicationSPI application) { this.DoForServicesInPassivationOrder(application, instance => instance.DisableLazyActivation()); LinkedList <Exception> list = null; this.DoForServicesInPassivationOrder(application, instance => { try { instance.RunPassivationActionIfNeeded(); } catch (Exception exc) { if (list == null) { list = new LinkedList <Exception>(); } list.AddLast(exc); } }); if (list != null && list.Any()) { throw new AggregateException(list); } }
private void DoForServicesInPassivationOrder(ApplicationSPI application, Action <ServiceCompositeInstanceImpl> action) { foreach (CompositeInstanceStructureOwner structureOwner in this.GetAllStructureOwners(application, false)) { // Don't need to get services which are not created //this.GetAllModels( structureOwner, false ).OfType<ServiceCompositeModel>().Where(model => model.SpecialMethods.Any(sMethod => sMethod.AllAttributes.OfType<PassivateAttribute>().Any())) foreach (var service in this.ReOrderExistingServicesOfServiceContainer(this.GetServiceContainerFor(structureOwner).ExistingServices)) { action((ServiceCompositeInstanceImpl)service); } } }
public override void ApplicationActivating(ApplicationSPI application) { foreach (var structureOwner in this.GetAllStructureOwners(application, true)) { foreach (var model in this.GetAllModels(structureOwner, true).OfType <ServiceCompositeModel>().Where(model => model.ActivateWithApplication)) { ((ServiceCompositeInstanceImpl)this.CreateInstance(structureOwner, model, model.PublicTypes, model.UsesContainer)).RunActivationActionIfNeeded(); } foreach (var existingService in this.ReOrderExistingServicesOfServiceContainer(this.GetServiceContainerFor(structureOwner).ExistingServices)) { ((ServiceCompositeInstanceImpl)existingService).RunActivationActionIfNeeded(); } } }
protected abstract IEnumerable <CompositeInstanceStructureOwner> GetAllStructureOwners(ApplicationSPI application, Boolean isActivation);
public virtual void ApplicationPassivating(ApplicationSPI application) { // Nothing to do }
protected override IEnumerable <CompositeInstanceStructureOwner> GetAllStructureOwners(ApplicationSPI application, Boolean isActivation) { // Perform BFS on dependency hierarchy var result = ((LayeredApplicationModel)application.ApplicationModel).TopLevelLayers.SelectMany(layerModel => layerModel.AsBreadthFirstEnumerable(model => model.UsedLayerModels)); if (isActivation) { result = result.Reverse(); } return(result .Distinct() .Select(layer => ((LayeredApplicationImpl)application).GetInstanceForModel(layer)) .SelectMany(layerInstance => layerInstance.LayerModel.ModuleModels.Select(moduleModel => layerInstance.GetInstanceForModel(moduleModel)))); }
/// <summary> /// Creates new instance of <see cref="ApplicationCreationArgs"/>. /// </summary> /// <param name="instance">The newly created application instance.</param> /// <exception cref="ArgumentNullException">If <paramref name="instance"/> is <c>null</c>.</exception> public ApplicationCreationArgs(ApplicationSPI instance) { ArgumentValidator.ValidateNotNull("Application instance", instance); this._instance = instance; }
protected override IEnumerable <CompositeInstanceStructureOwner> GetAllStructureOwners(ApplicationSPI application, Boolean isActivation) { return(Enumerable.Repeat((SingletonApplication)application, 1)); }