public ContainerService Instantiate(Type type, bool crearteNew, IObjectAccessor arguments) { var builder = new ContainerService.Builder(type, this, crearteNew, arguments); if (builder.Status != ServiceStatus.Ok) return builder.Build(); var declaredName = builder.GetDeclaredName(); if (!constructingServices.Add(declaredName)) { var previous = GetTopBuilder(); if (previous == null) throw new InvalidOperationException(string.Format("assertion failure, service [{0}]", declaredName)); var message = string.Format("cyclic dependency {0}{1} -> {0}", type.FormatName(), previous.Type == type ? "" : " ...-> " + previous.Type.FormatName()); var cycleBuilder = new ContainerService.Builder(type, this, false, null); cycleBuilder.SetError(message); return cycleBuilder.Build(); } stack.Add(builder); var expandResult = TryExpandUnions(Container.Configuration); if (expandResult != null) { var poppedContracts = Contracts.PopMany(expandResult.Length); foreach (var c in expandResult.CartesianProduct()) { var childService = Resolve(new ServiceName(builder.Type, c)); builder.LinkTo(Container.containerContext, childService, null); if (builder.Status.IsBad()) break; } Contracts.AddRange(poppedContracts); } else Container.Instantiate(builder); stack.RemoveLast(); constructingServices.Remove(declaredName); return builder.Build(); }