vendredi 21 mai 2021

How to deal with instantiated dependencies?

Dealing with instantiated dependencies.

So a general question: How to deal with dependencies that is instantiated?

Say I have two functions:

public class Manager : ScriptableObject
{
    private var data;
    private void GetDataFromTextAsset() => data = BuildData();
    public bool IsValidInput(var input)
    {
        if(data.SomeAspectIsTrue)
            return true;
        return false;
    }
}

along with:

public class User
{
    public void SomeFunction(var input)
    {
        if(_manager.IsValidInput(input))
            DoStuff();
    }  
}

what is the proper way to solve such a dependency, that decouples the two classes, is scalable and testable?

I want to use Zenject, but I'm not sure if that is good for this specific issue?

Also I guess singletons are out the window?

Aucun commentaire:

Enregistrer un commentaire