How better to resolve dependencies in object created by factory?

后端 未结 1 1499
南笙
南笙 2020-12-02 02:53

For example I have dependency:

public interface IMyDependency
{
}

public class MyDependency : IMyDependency
{
}

That injects in MyClass ob

相关标签:
1条回答
  • 2020-12-02 03:33

    For dependencies that are independent of the instance you're creating, inject them into the factory and store them until needed.

    For dependencies that are independent of the context of creation but need to be recreated for each created instance, inject factories into the factory and store them.

    For dependencies that are dependent on the context of creation, pass them into the Create method of the factory.

    0 讨论(0)
提交回复
热议问题