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
Well, you can always inject an Abstract Factory into your consumer and use it to create the locally scoped objects.
This is sometimes necessary. See these examples:
However, in general we tend to not use DI for Entities, but mostly for Services. Instead, Entities are usually created through some sort of Repository.
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)