I've implemented two services. One that pulls data from a Country API and another that pulls data from a County API.
I like to keep my controllers clean, so I'm curious if it's a good idea to combine my services together instead of keeping them apart.
I'm not exactly sure what constitutes tight coupling and when it's appropriate or not.
Should I go down this route:
public async Task<IActionResult> Get(
[FromQuery] double latitude,
[FromQuery] double longitude
{
var countryService = new CountryService();
var countryData = await countryService.Get(latitude, longitude);
var countyService = new CountyService();
var countyData = await countyService.Get(latitude, longitude);
return Ok(new Data(countryData, countyData);
}
OR
public async Task<IActionResult> Get(
[FromQuery] double latitude,
[FromQuery] double longitude
{
var combinedService = new CombinedService();
Data combinedData = await combinedService.Get(latitude, longitude);
return Ok(combinedData);
}
Tight coupling is an excellent idea when you sense cohesion on the domain level. In Eric Evans' book DDD the term Bounded Context is defined. Think about it this way: how much information/knowledge is shared between the two parts? If it's a relevantly high percentage you may as well couple them because they are already on the domain level. This also is affine to Larmans' GRASP definition of Information Expert.
More about this here.