Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug information for Scopes #993

Open
dotnetjunkie opened this issue Mar 11, 2024 · 2 comments
Open

Add debug information for Scopes #993

dotnetjunkie opened this issue Mar 11, 2024 · 2 comments
Milestone

Comments

@dotnetjunkie
Copy link
Collaborator

dotnetjunkie commented Mar 11, 2024

Currently, it's hard to see if multiple Scope references point to the same scope, or to different instances. It would, therefore, be useful, for debugging purposes to see a unique instance number, just like Container instances already have an unique internal id. For instance something like:

private readonly long id;

public override ToString()
{
    if (this.ParentScope is null && this.Container is null)
    {
         return "Scope #" + this.id;
    }
    
    if (this.ParentScope is null)
    {
         return "Scope #" + this.id + " for Container #" + this.Container.Id;
    }

    return "Scope #" + this.id + " for Parent #" + this.ParentScope.Id + 
        " for Container #" + this.Container.Id;
}
@dotnetjunkie dotnetjunkie added this to the v5.5 milestone Mar 11, 2024
@wleader
Copy link

wleader commented Mar 13, 2024

I like this, but you may want to reserve overriding .ToString() for something that is an actual string representation of the object (although I am having trouble imagining what that would be.) A slightly more formal way of providing this kind of debug time information is to use a DebuggerDisplay attribute.

https://learn.microsoft.com/en-us/visualstudio/debugger/using-the-debuggerdisplay-attribute?view=vs-2022

@dotnetjunkie
Copy link
Collaborator Author

As a matter of fact, Simple Injector already uses [DebuggerDisplay] extensively. But I do agree with you, that a DebuggerDisplayAttribute would be a better fit here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants