Skip to content

Conversation

@Antoshidza
Copy link
Contributor

Description

Provides functionality to have multiple inherited containers.
Instead of having one Container Parent field Container class now have List<Container> Parents. The major part of changes are in ContainerBuilder which have now AddParent(Container), RemoveParent(Container), RemoveAllParents() methods instead of one SetParent(Container). Resulting Container includes all unique resolvers from all of its parents, for doing that ContainerBuilder uses HashSet to distinguish resolvers, which is extra hash calculation per resolver.

This changes not only breaking because of ContainerBuilder API but as this repo author @gustavopsantos mentioned in our discussion are also can produce complex and error prone container compositions. For defending of that I can say that this functionality doesn't force users to use multiple inheritance and also doesn't change very basic usage of Reflex, but for those who wants to have complex setups there is corresponding functionality which requires more control and attention.

I guess there is a lot to discuss and change if this idea is even acceptable, so I have not changed documentations.

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

In code bellow in ReflexSampleProjectInstaller I've changed code so it detach all scenes from project scope and also create two parent containers and one child container from scratch.

public class ReflexSampleProjectInstaller : MonoBehaviour, IInstaller
{
    [SerializeField] private PickupSoundEffect _pickupSoundEffectPrefab;

    public void InstallBindings(ContainerBuilder containerBuilder)
    {
        containerBuilder.AddSingleton(_pickupSoundEffectPrefab);

        SceneScope.OnSceneContainerBuilding += (scene, builder) => 
        {
            // Debug.Log($"Build {scene.name} with builder {builder.Name}, parent_container: {(builder.Parent == null ? "None" : builder.Parent.Name)}");
            builder.RemoveAllParents();
        };

        var parent0 = new ContainerBuilder().SetName("Parent_0").Build();
        var parent1 = new ContainerBuilder().SetName("Parent_1").Build();
        var child = new ContainerBuilder().SetName("Child").AddParent(parent0).AddParent(parent1).Build();
    }
}

There are also few tests added in ScopedContainerTests.cs.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings
  • I have checked that Reflex.GettingStarted still runs nicely

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant