我有一个模型类,它从我的存储库类中的“GetById”方法加载.我现在需要向此实体添加其他属性,这些属性不保存在数据库中,而是由服务类计算.就像是:
public class MyEntity { public int ThingId { get; set; }; public string ThingName { get; set; } // Set from the service public int WooFactor { get; set; } } public class WooFactorGenerator { public int CalculateWooFactor(MyEntity thing); // Hits other services and repo's to eventually determine the woo factor. } // Code to get a "MyEntity": var myEntity = repo.GetById(1); var gen = new WooFactorGenerator(); myEntity.WooFactor = gen.CalculateWooFactor(myEntity);
因此,为了加载/饱和MyEntity对象,我需要从db加载,然后调用生成器来确定“woo factor”(哼).这段代码应该从架构的角度来看?目前的想法:
1)在存储库中:如果我在这里添加它,我觉得我对repo负有太多责任.
2)在“MyEntity”课程中.在这里添加可能在访问WooFactor时加载WooFactor的代码.这会给MyEntity添加很多依赖项.
3)一个单独的服务类 – 似乎过度和不必要.