Is DDD Factory allowed to set properties directly for domain object? Such as:
public class DomainObjectFactory
{
public DomainObject CreateForUser(int userId)
{
var domainObject = new DomainObject();
domainObject.UserId = userId;
}
}
The normal way to create domain entities would be to do so with constructor(s). So you accept required parameters through one or more constructors.
If you use domain factories, nothing changes that. A domain factory is used when entity creation is more complex, for example, from multiple objects or where some logic is involved during the creation, but you would still use the entity's constructor to create them.