我试图避免此类ContentDomain成为神级和隔离功能集成到特定的类别(按照SRP)这样设计模式的选择域/业务层
ContentDomain:
public class ContentDomain : IContentDomain
{
private ISolutionDomain solutionDomain;
private IServiceDomain serviceDomain;
private IPhaseDomain phaseDomain;
public ContentDomain(IUnitOfWork _unitOfWork)
{
this.solutionDomain = new SolutionDomain(_unitOfWork);
this.serviceDomain = new ServiceDomain(_unitOfWork);
this.phaseDomain = new PhaseDomain(_unitOfWork);
}
public ISolutionDomain SolutionDomain { get { return solutionDomain; } }
public IServiceDomain ServiceDomain { get { return serviceDomain; } }
public IPhaseDomain PhaseDomain { get { return phaseDomain; } }
}
一个特定的领域类的
public class SolutionDomain : BaseDomain, ISolutionDomain
{
public SolutionDomain(IUnitOfWork _unitOfWork)
: base(_unitOfWork)
{
}
public IEnumerable<Solution> GetAllSolutions()
{
return base.GetAll<Solution>(sol => sol.IsActive == true).OrderBy(rec => rec.Name).Select(rec => rec).ToList();
}
}
而且现在我的控制器只知道ContentDomain和从SolutionDomain/ServiceDomain/PhaseDomain调用具体方法为,并在需要的时候:
public ContentController(IContentDomain domain, ICurrentUser currentUser)
: base(domain, currentUser)
{
}
public ActionResult Home()
{
var myServices = domain.ServiceDomain.GetServicesWithDetails(rec => rec.CreatedBy == currentUser.Name);
var viewModelCollection = myServices.Select(service => new DashboardViewModel(service, domain));
if (currentUser.IsInRole("SU"))
return View("Home_SU", viewModelCollection);
else if (currentUser.IsInRole("Reviewer"))
return View("Home_Reviewer", viewModelCollection);
else return View("Home", viewModelCollection);
}
请注意,在首页的第一条语句()
domain.ServiceDomain.GetServicesWithDetails(rec => rec.CreatedBy == currentUser.Name);
我发现自己混合门面和ContentDomain类中的组合。
现在的问题是 -
- 是否合理使用组成直通门面公开特定域的功能?
- 如果不是的话,那可能是什么情况?
- 机会我违反了这种方法的任何固体原则?
我觉得很难理解这个问题,因为它太抽象了(一切都是一个界面)。除了'currentUser.Name'之外,我并不真正看到你所暴露的“特定域功能”。你的问题3太宽泛。设计是各种各样的妥协,所以答案很可能(在一个复杂的项目中)在某处违反了SOLID。 TL; DR你的问题需要更加具体才能得到答案。 – Fuhrmanator
SolutionDomain类表示作为domain公开的特定域功能。解决方案域 –