Castle.MicroKernel.Handlers.AbstractHandler.DependencySatisfied C# (CSharp) Method

DependencySatisfied() protected method

Invoked by the kernel when one of registered dependencies were satisfied by new components registered.
Handler for the event IKernelEvents.HandlerRegistered
protected DependencySatisfied ( IHandler handler, bool &stateChanged ) : void
handler IHandler
stateChanged bool
return void
		protected void DependencySatisfied(IHandler handler, ref bool stateChanged)
		{
			// Check within the handler

			if (customParameters != null && customParameters.Count != 0)
			{
				DependencyModel[] dependencies = Union(DependenciesByService.Values, DependenciesByKey.Values);

				foreach (DependencyModel dependency in dependencies)
				{
					if (!HasCustomParameter(dependency.DependencyKey))
					{
						continue;
					}

					if (dependency.DependencyType == DependencyType.Service)
					{
						DependenciesByService.Remove(dependency.TargetType);
					}
					else
					{
						DependenciesByKey.Remove(dependency.DependencyKey);
					}
				}
			}

			// Check within the Kernel

			Type[] services = new Type[DependenciesByService.Count];
			DependenciesByService.Keys.CopyTo(services, 0);

			foreach (Type service in services)
			{
				if (HasValidComponent(service))
				{
					DependenciesByService.Remove(service);
					AddGraphDependency(kernel.GetHandler(service).ComponentModel);
				}
			}

			String[] keys = new String[DependenciesByKey.Keys.Count];
			DependenciesByKey.Keys.CopyTo(keys, 0);

			foreach (String compKey in keys)
			{
				if (HasValidComponent(compKey) || HasCustomParameter(compKey))
				{
					DependenciesByKey.Remove(compKey);
					AddGraphDependency(kernel.GetHandler(compKey).ComponentModel);
				}
			}

			if (DependenciesByService.Count == 0 && DependenciesByKey.Count == 0)
			{
				SetNewState(HandlerState.Valid);
				stateChanged = true;

				DisconnectEvents();

				// We don't need these anymore

				dependenciesByKey = null;
				dependenciesByService = null;
			}
		}