Skip to content

Potentially misconfigured lifestyle for LazyOfTComponentLoader  #27

@kimschurmann

Description

@kimschurmann

When running a diagnostic on lifestyles for the container, potential misconfigurations are highlighted.

Following dependency chains have inconsistent accessibility:

  • ITask (Singleton) -> Lazy1 (Transient)
  • IStep1 (Singleton) -> Lazy1 (Transient)
  • IStep1 (Singleton) -> Lazy1 (Transient)
  • IStep1 (Singleton) -> Lazy1 (Transient)

Reproduce with the following code:

`public void EnsureMatchingLifestylesForKernel()
{
var host = (IDiagnosticsHost) _kernel.GetSubSystem(SubSystemConstants.DiagnosticsKey);
IHandler[][] misconfigurations = host.GetDiagnostic().Inspect();

        if (misconfigurations.Any())
        {
            var diagnosticOutput = new StringBuilder();
            diagnosticOutput.AppendLine("Following dependency chains have inconsistent accessibility:" + Environment.NewLine);

            foreach (IHandler[] misconfiguration in misconfigurations)
            {
                diagnosticOutput.AppendLine(
                    string.Join(
                        " -> ",
                        misconfiguration
                            .Where(m => m.ComponentModel.Services.Any())
                            .Select(m => $"{m.ComponentModel.Services.First().Name} ({m.ComponentModel.LifestyleType})")));
            }

            //TODO: This should be an exception 
            _logger.LogWarning(Target.Service, diagnosticOutput.ToString());
        }
    `

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions