Я работаю над проектом со сложным бизнесом. Рассмотрим два класса: AccountService и SchoolService.
Я использую Unity и преобразователь зависимостей веб-API для реализации внедрения зависимостей в конструкторе.
Школьная служба использует службу учетной записи в некоторых методах, также служба учетной записи использует школьную службу. Все это необходимо в бизнес-проекте. Это вызовет циклическую зависимость, и невозможно будет перемещать методы из одного класса в другой.
Не могли бы вы представить, как это решить?
Вот пример:
public class SchoolBLC : ISchoolBLC
{
public School GetSchool(int schoolId)
{
...
}
public bool RenewRegistration(int accountId)
{
bool result = true;
IAccountBLC accountBLC = new AccountBLC();
// check some properties related to the account to decide if the account can be renewed
// ex : the account should not be 5 years old
// check the account created date and do renewal
return result;
}
}
public class AccountBLC : IAccountBLC
{
public void ResetAccount(int accountId)
{
ISchoolBLC schoolBLC = new SchoolBLC();
School accountSchool = schoolBLC
// get the school related to the account to send a notification
// and tell the school that the user has reset his account
// reset account and call the school notification service
}
public Account GetAccount(int accountId)
{
...
}
}
Эти два класса ссылаются друг на друга, это ситуация для 70% BLC в проекте.