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

Default Test and Run mode #938

Closed
adamradocz opened this issue Jul 24, 2022 · 8 comments · Fixed by #939
Closed

Default Test and Run mode #938

adamradocz opened this issue Jul 24, 2022 · 8 comments · Fixed by #939
Labels

Comments

@adamradocz
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Kent Boogaart in the "You, I, and ReactiveUI" book recommends overriding the ModeDetector in order to boost its performance. But implementing the same CustomModeDetector in every project is a little bit cumbersome.

Describe the solution you'd like
The default implementation of the Run and Test mode.

Example:

public sealed class Mode : IModeDetector
{
    private readonly bool _inUnitTestRunner;

    public static readonly Mode Run = new(false);
    public static readonly Mode Test = new(true);

    private Mode(bool inUnitTestRunner)
    {
        _inUnitTestRunner = inUnitTestRunner;
    }

    public bool? InUnitTestRunner() => _inUnitTestRunner;
}

Usage in the Run environment:

public App()
{
    Splat.ModeDetector.OverrideModeDetector(Mode.Run);
    
    //... the rest of the startup code.
}

Usage in the Test environment:

Splat.ModeDetector.OverrideModeDetector(Mode.Test);

I can make a PR if you like this solution.

@glennawatson
Copy link
Contributor

Sounds like a good PR. Doesn't break existing functionality. Go for it.

ChrisPulman added a commit that referenced this issue Jul 24, 2022
@adamradocz
Copy link
Contributor Author

@glennawatson @ChrisPulman
I've been thinking about the naming of Mode.Run and it feels a little bit clumsy.
Wouldn't the Mode.App be better, or the Mode.Run is just fine?

@anaisbetts
Copy link
Member

recommends overriding the ModeDetector in order to boost its performance.

I guess I question this a bit - if ModeDetector is slow, why don't we just fix it? That seems better than trying to make "official workarounds" for our own code!

@glennawatson
Copy link
Contributor

glennawatson commented Jul 25, 2022

Probably can make it faster for newer SDK style applications .net 6 and above, since there are now "UseWindowsForms" and "UseWPF" and "UseMaui" msbuild properties. Older framework applications we still support have no such joy.

@glennawatson
Copy link
Contributor

I'll make an issue so we can target those properties at the very least to give the user a speed boost in those environments.

@glennawatson
Copy link
Contributor

#940

@adamradocz
Copy link
Contributor Author

ModeDetector uses reflection in order to detect the environment. No matter how you optimize it, it's always going to be a magnitude slower than a predefined method that just returns true or false.

@github-actions
Copy link

github-actions bot commented Aug 9, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants