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 Avalonia Support #1025

Merged
merged 6 commits into from
Jul 24, 2023
Merged

Add Avalonia Support #1025

merged 6 commits into from
Jul 24, 2023

Conversation

ChrisPulman
Copy link
Member

@ChrisPulman ChrisPulman commented Jul 20, 2023

What kind of change does this PR introduce?

Feature
Fix for #1024

What is the current behaviour?

Avalonia.ReactiveUI has some support for ReactiveUI within the Avalonia packages, but not extended capabilities.

What is the new behaviour?

ReactiveUI.Avalonia now gives the option to use the components from ReactiveUI and Splat
Extensions will be ReactiveUI.Avalonia.XXXX and where possible be a single dll for all ReactiveUI Avalonia features

What might this PR break?

Avalonia.ReactiveUI will now become ReactiveUI.Avalonia

Please check if the PR fulfils these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Other information:

@ChrisPulman ChrisPulman marked this pull request as draft July 20, 2023 21:59
@codecov
Copy link

codecov bot commented Jul 21, 2023

Codecov Report

Patch coverage: 75.60% and project coverage change: +0.01 🎉

Comparison is base (7f31c43) 75.43% compared to head (6dcf9e3) 75.45%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1025      +/-   ##
==========================================
+ Coverage   75.43%   75.45%   +0.01%     
==========================================
  Files          93       93              
  Lines        4388     4387       -1     
==========================================
  Hits         3310     3310              
+ Misses       1078     1077       -1     
Impacted Files Coverage Δ
src/Splat.DryIoc/SplatDryIocExtensions.cs 100.00% <ø> (ø)
src/Splat.Prism/SplatContainerExtension.cs 52.05% <0.00%> (-1.47%) ⬇️
src/Splat.Drawing/Colors/SplatColor.cs 81.66% <83.33%> (-0.16%) ⬇️
src/Splat.DryIoc/DryIocDependencyResolver.cs 87.96% <95.65%> (+2.24%) ⬆️
...DependencyInjection/MicrosoftDependencyResolver.cs 84.61% <100.00%> (+0.19%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Leon99
Copy link

Leon99 commented Jul 22, 2023

Can we have something like this, to allow for more flexibility but still ensure the right order?

    public static AppBuilder UseReactiveUIWithDIContainer<TContainer>(this AppBuilder builder, 
        Func<TContainer> containerFactory, Action<TContainer> containerConfig, Func<TContainer, IDependencyResolver> dependencyResolverFactory)
    {
        return builder switch
        {
            null => throw new ArgumentNullException(nameof(builder)),
            _ => builder.UseReactiveUI().AfterPlatformServicesSetup(_ =>
            {
                ArgumentNullException.ThrowIfNull(containerFactory);
                ArgumentNullException.ThrowIfNull(containerConfig);
                ArgumentNullException.ThrowIfNull(dependencyResolverFactory);
                
                var container = containerFactory();
                Locator.CurrentMutable.RegisterConstant(container, typeof(Container));
                var dependencyResolver = dependencyResolverFactory(container);
                Locator.SetLocator(dependencyResolver);
                RxApp.MainThreadScheduler = AvaloniaScheduler.Instance;
                containerConfig(container);
            })
        };
    }

@ChrisPulman ChrisPulman marked this pull request as ready for review July 24, 2023 00:51
@ChrisPulman
Copy link
Member Author

I have added as many tests as I could without tripping over the issue of the container having already been built or the AppBuilder already having been built. We will have to find a way to test more at a later date.

@ChrisPulman ChrisPulman merged commit 45e67e2 into main Jul 24, 2023
3 checks passed
@ChrisPulman ChrisPulman deleted the CP_AddAvaloniaSupport branch July 24, 2023 01:11
@ChrisPulman
Copy link
Member Author

Can we have something like this, to allow for more flexibility but still ensure the right order?

    public static AppBuilder UseReactiveUIWithDIContainer<TContainer>(this AppBuilder builder, 
        Func<TContainer> containerFactory, Action<TContainer> containerConfig, Func<TContainer, IDependencyResolver> dependencyResolverFactory)
    {
        return builder switch
        {
            null => throw new ArgumentNullException(nameof(builder)),
            _ => builder.UseReactiveUI().AfterPlatformServicesSetup(_ =>
            {
                ArgumentNullException.ThrowIfNull(containerFactory);
                ArgumentNullException.ThrowIfNull(containerConfig);
                ArgumentNullException.ThrowIfNull(dependencyResolverFactory);
                
                var container = containerFactory();
                Locator.CurrentMutable.RegisterConstant(container, typeof(Container));
                var dependencyResolver = dependencyResolverFactory(container);
                Locator.SetLocator(dependencyResolver);
                RxApp.MainThreadScheduler = AvaloniaScheduler.Instance;
                containerConfig(container);
            })
        };
    }

This exists in all the packages in addition to the wrapped versions. Some DI containers will require some additional calls to complete the process when using this method.

@github-actions
Copy link

github-actions bot commented Aug 8, 2023

This pull request 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 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants