-
Notifications
You must be signed in to change notification settings - Fork 0
7. User Service
The UserService class within the RexStudios.LanguageDependentNotification namespace serves as a central component for retrieving user language information from Dynamics CRM. It encapsulates the logic for fetching user language preferences and details, promoting encapsulation and modular design. By adhering to the Dependency Injection principle, it receives repository implementations through its constructor, ensuring loose coupling and facilitating unit testing. Additionally, it encapsulates all repository interactions, providing developers with a single entry point for accessing user-related data.
-
Dependency Injection: The class employs the Dependency Injection pattern to inject instances of repository interfaces (
IUserSettingsRepo,IUserRepo,ILanguageCodeRepo) into its constructor. This pattern enables the class to decouple from specific repository implementations, promoting flexibility and testability.
- GetUserLanguageFromUser(Guid userId): Retrieves the language code associated with a user based on the provided user ID. It first attempts to fetch the language information from user details. If not found, it falls back to retrieving the language from user preferences.
-
GetLangauageEntity(Guid userId): Internal method that retrieves the language code entity associated with a user. It first checks the user details, and if not found, it invokes
GetUserLanguageFromUserPreferences. -
GetUserLanguageFromUserPreferences(Guid UserId): Retrieves the user's preferred language from user settings by invoking the
GetUserLanguageIdmethod of theIUserSettingsRepo.
The UserService class encapsulates all interactions with repository interfaces (IUserSettingsRepo, IUserRepo, ILanguageCodeRepo). This encapsulation shields consuming applications from the complexities of repository instantiation and configuration, providing a simplified interface for accessing user-related data. Developers can directly consume the UserService class without needing to manage repository instances separately. Additionally, the class can be easily extended or overridden to accommodate specific business requirements by subclassing or method overloading.
Developers can utilize the UserService class to obtain user language information from Dynamics CRM by invoking the GetUserLanguageFromUser method, passing the user ID as a parameter. The class encapsulates the complexity of fetching user language details and preferences, providing a simplified interface for consuming applications. By leveraging the IUserService interface, developers can maintain a clear separation of concerns and easily swap out implementations if required. This promotes code maintainability and extensibility, ensuring that the user service remains adaptable to future changes in the application requirements.