Localization of authentication messages from domain objects (objects)

It is not my intention to participate in debates on verification in DDD, where the code belongs, etc., but to focus on one of the possible approaches and how to solve localization problems. I have the following behavior (method) on one of my domain objects (objects) that illustrate the scenario:

public void ClockIn()
{
    if (WasTerminated)
    {
        throw new InvalidOperationException("Cannot clock-in a terminated employee.");
    }

    ClockedInAt = DateTime.Now;
    :
}

As you can see, when the ClockIn method is called, the method checks the state of the object to ensure that Employee has not been interrupted. If the Employee has been terminated, we raise an exception consistent with the “Do not allow your entities to enter an invalid status” approach.

, . ( ) (ILocalizationService), MEF , . , DI, / , . DDD.

, , DDD, , , . , , , ?

, - /. , - DDD.

UPDATE

, , ( ILocalizationService). Visual Studio .

, , RESTful. , -. , , , .. ( ), , HTTP , (Accept-Language).

+3
4

, , . , , , ( , , , , ).

, , . .

+2

, - .

, ,

throw new InvalidOperationException("ERROR_TERMINATED_EMPLOYEE_CLOCKIN");

, , , (log, , ).

+1

/, , . , "DDD , " - , .

0

.

, :

public class EmployeeServiceImpl implements EmployeeService {

   public void ClockEmployeeIn(Employee employee) throws InvalidOperationException {
      if (employee.isTerminated()) {
          // Localize using a resource lookup code..
          throw new InvalidOperationException("Error_Clockin_Employee_Terminated");      
      }       
      employee.setClockedInAt(DateTime.Now);
   }
}

Then you can implement this service using your DI infrastructure at the moment when you make a clockin call and use this service to isolate domain objects from changes in business logic.

0
source

All Articles