Exemple #1
0
        public void WriteConstructionLog(ConstructionLogContext context)
        {
            var usedContracts     = UsedContracts;
            var attentionRequired = Status.IsBad() ||
                                    Status == ServiceStatus.NotResolved && (context.UsedFromDependency == null ||
                                                                            context.UsedFromDependency.Status ==
                                                                            ServiceStatus.NotResolved);

            if (attentionRequired)
            {
                context.Writer.WriteMeta("!");
            }
            var formattedName = context.UsedFromDependency == null?Type.FormatName() : context.UsedFromDependency.Name;

            context.Writer.WriteName(formattedName);
            if (usedContracts != null && usedContracts.Length > 0)
            {
                context.Writer.WriteUsedContract(InternalHelpers.FormatContractsKey(usedContracts));
            }
            var name = new ServiceName(Type, usedContracts);

            if (!context.Seen.Add(name))
            {
                if (context.UsedFromService != null && context.UsedFromService.Name.Equals(name) &&
                    context.UsedFromDependency != null && context.UsedFromDependency.Comment != null)
                {
                    context.Writer.WriteMeta(" - ");
                    context.Writer.WriteMeta(context.UsedFromDependency.Comment);
                }
                context.Writer.WriteNewLine();
                return;
            }
            if (Instances.Length > 1)
            {
                context.Writer.WriteMeta("++");
            }
            if (Status == ServiceStatus.Error)
            {
                context.Writer.WriteMeta(" <---------------");
            }
            else
            {
                var logComment = comment;
                if (logComment == null && context.UsedFromDependency != null &&
                    context.UsedFromDependency.Status != ServiceStatus.Error)
                {
                    logComment = context.UsedFromDependency.Comment;
                }
                if (logComment != null)
                {
                    context.Writer.WriteMeta(" - ");
                    context.Writer.WriteMeta(logComment);
                }
            }
            if (context.UsedFromDependency != null && context.UsedFromDependency.Status == ServiceStatus.Ok &&
                (context.UsedFromDependency.Value == null || context.UsedFromDependency.Value.GetType().IsSimpleType()))
            {
                context.Writer.WriteMeta(" -> " + InternalHelpers.DumpValue(context.UsedFromDependency.Value));
            }
            else if (Instances.Length == 1 && Instances[0].IsConstant)
            {
                ValueFormatter.WriteValue(context, Instances[0].Instance, true);
            }
            if (initializing)
            {
                context.Writer.WriteMeta(", initializing ...");
            }
            else if (disposing)
            {
                context.Writer.WriteMeta(", disposing ...");
            }
            context.Writer.WriteNewLine();
            if (dependencies != null)
            {
                foreach (var d in dependencies)
                {
                    context.Indent++;
                    context.UsedFromService = this;
                    d.WriteConstructionLog(context);
                    context.Indent--;
                }
            }
        }
 public string FormatContracts()
 {
     return(Contracts.IsEmpty() ? "" : "[" + InternalHelpers.FormatContractsKey(Contracts) + "]");
 }