IoC Dependency Injection for stateful objects (not global)

前端 未结 2 849
北荒
北荒 2021-02-06 08:05

I\'m new to this IoC and DI business- I feel like I get the concept if you are passing along objects that are of a global scope, but I don\'t get how it works when you need to p

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-06 09:00

    When you construct an service object (e.g. WriteFileService), you inject into it things it needs internally to complete it's job. Perhaps it needs a filesystem object or something.

    The Person object in your example should be passed to the service object as a parameter to a method call. e.g. writeFileService.write(person)

提交回复
热议问题