**Case 1.** **Doing validation in application layer:** If we call repository `countryRepo.getCountryByCountryAlpha3Code()` in application layer and then if the value is correct and valid part of system we can then pass the `createValidEntity()` and if not then can throw the error directly in application layer use-case. **Issue:** - This validation will be repeated in multiple use-case if same validation need to be checked in other use-cases if its application layer concern - Here the business logic is now a part of application service layer **Case 2** Validating the country code in its value object class or domain service in Domain Layer Doing this will keep business logic inside domain layer and also won't violate DRY principle. import { ValueObject } from '@shared/core/domain/ValueObject'; import { Result } from '@shared/core/Result'; import { Utils } from '@shared/utils/Utils'; interface CountryAlpha3CodeProps { value: string; } export class CountryAlpha3Code extends ValueObject<CountryAlpha3CodeProps> { // Case Insensitive String. Only printable ASCII allowed. (Non-printable characters like: Carriage returns, Tabs, Line breaks, etc are not allowed) get value(): string { return this.props.value; } private constructor(props: CountryAlpha3CodeProps) { super(props); } public static create(value: string): Result<CountryAlpha3Code> { return Result.ok<CountryAlpha3Code>(new CountryAlpha3Code({ value: value })); } } - Is it good to call the repository from inside domain layer (Service or VO (not recommended) ) then dependency flow will change? - If we trigger event how to make it synchronous? - What are some better ways to solve this?
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)