I am trying to avoid this class ContentDomain becoming a God class and isolating the functionality into specific classes (to follow SRP) like this
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; } }
}
One of the specific domain classes
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();
}
}
And now my controller is only aware of ContentDomain and calls specific methods from SolutionDomain/ServiceDomain/PhaseDomain as and when needed:
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);
}
Notice the first statement in Home()
domain.ServiceDomain.GetServicesWithDetails(rec => rec.CreatedBy == currentUser.Name);
I find myself mixing Facade and Composition in ContentDomain class.
Now the questions are-
- Is it reasonable to expose specific domain functionality thru Facade using composition?
- If not, what could be the catch?
- Chances I am violating any of the SOLID principles with this approach?