A dependency injection container can handle the creation of all objects. This includes your DIC using factories to create specific objects that use the factory pattern.
I like loading DICs with closures that create objects. This way all objects are lazy loaded only on demand, but I can still have a lot of flexibility when creating objects.
You can write so that your datamapper gets an empty uservalue object and then initializes the object data based on the database data. An alternative is to create a tight connection between your data classes and service classes, as one creates the other on its own.
Trying to separate your framework from your business logic should not mean that it does not allow two to touch, just that the business logic code is not included in your infrastructure code. Using DIC to create objects that are used for business logic does not mean that your DIC has business logic.
source share