Ejemplo n.º 1
0
		// Called by the UITask when this node becomes the current node
		internal void EnterNode(UINode prevNode)
		{
			// Remember what the previous node was. This is useful for modal windows.
			_prevNode = prevNode;

			// If the node is being entered for the first time, its service container will be null
			// and has to be created.
			if (Container == null)
			{
				IServiceContainer parentContainer = Task.ServiceLocator.GetInstance<IServiceContainer>();
				Verify.IsNotNull(parentContainer);

				// Do not assign the container to _container yet -- wait until all the registration is 
				// complete. That way if one of the registrations throws an exception ,we are not left with
				// a node whose container is not fully initialised.
				IServiceContainer nodeContainer = parentContainer.CreateChildContainer();

				var windsorContainer = nodeContainer.Locator.GetInstance<IWindsorContainer>();

				nodeContainer.RegisterInstance(this);

				windsorContainer.Register(
					Component.For<INavigateCommand>()
						.UsingFactoryMethod(CreateNavigateCommand)
						.LifestyleTransient());

				// If the presenter is a concrete type and has not been registered yet, then register it
				// with the container.
				if (PresenterType != null && !PresenterType.IsInterface && !nodeContainer.IsTypeRegistered(PresenterType))
				{
					nodeContainer.RegisterType(PresenterType, null, null, ServiceLifecycle.PerRequest);
				}

				// If the view type has not been declared
				if (DeclaredViewType == null)
				{
					// If the inferred type is a concrete type and has not been registered, then register it
					if (InferredViewType != null && !InferredViewType.IsInterface && !nodeContainer.IsTypeRegistered(InferredViewType))
					{
						nodeContainer.RegisterType(InferredViewType, ServiceLifecycle.PerRequest);
					}
				}
				else
				{
					if (!DeclaredViewType.IsInterface)
					{
						if (InferredViewType != null && InferredViewType.IsInterface)
						{
							// The view type is concrete, and the presenter type is an interface
							nodeContainer.RegisterType(InferredViewType, DeclaredViewType, ServiceLifecycle.PerRequest);
						}
						else
						{
							// Use the concrete view type by itself.
							nodeContainer.RegisterType(DeclaredViewType, ServiceLifecycle.PerRequest);
						}
					}
				}

				if (NestedTaskType != null)
				{
					nodeContainer.RegisterType(NestedTaskType, ServiceLifecycle.PerRequest);
				}

				// node container is now initialised, assign to the member variable
				Container = nodeContainer;
			}
		}
Ejemplo n.º 2
0
		private static SessionHolder GetSessionHolder(UINode node, string alias)
		{
			var sessionHolder = node.Task.GetNodeLifetimeObject<SessionHolder>(alias);
			if (sessionHolder == null)
			{
				sessionHolder = new SessionHolder
				{
					ShouldHaveSession = HasSessionAttribute(node.View)
										|| HasSessionAttribute(node.Presenter)
										|| HasSessionAttribute(node.ViewType)
										|| HasSessionAttribute(node.PresenterType)
				};
				node.Task.SetNodeLifetimeObject(alias, sessionHolder);
			}
			return sessionHolder;
		}