Let's say I have a User class that's partially populated via an ORM, but there are some pieces of data that are logically related to this entity that are provided from elsewhere.
public class User {
public int Id { get; set; }
public int ServiceId { get; set; }
public string FirstName => null; //this comes from somewhere else
public ICollection<Role> Roles { get; set; }
//etc...
}
Previously, in cases similar to this, I've been allowing a single interface to be injected into the domain model by the IOC container to handle this.
public class User {
public readonly IUserBehavior _userBehavior;
public User() {}
public User(IUserBehavior userBehavior) {
_userBehavior = userBehavior;
}
public int Id { get; set; }
public int ServiceId { get; set; }
public string FirstName => _behavior?.getFirstName(this);
public ICollection<Role> Roles { get; set; }
//etc...
}
I recently, however, tried switching from nHibernate to Entity Framework, which looks to make this impossible (at least, in so far as using constructor injection).
My options right now seem to be to move the service call (implementation details) to obtain the missing data directly into the entity or use a double dispatch pattern that seems rather off... Certain data properties of the type would have to be called in a special way. Were this performing an action to change state, I could see double dispatch making more sense. Alternatively, I suppose I could go back to nHibernate.
I guess what I'm asking is are any of my options actually "good", or is there some other option that I should consider?