Пока все в порядке.
К сожалению, я также хочу иметь возможность в полной мере использовать функции внедрения зависимостей в ASP.NET Core и реализовать реализацию службы с помощью DI.
У меня есть POC реализация:
Код: Выделить всё
public interface IRootService
{
INestedService NestedService { get; set; }
void DoSomething();
}
public class RootService : IRootService
{
public INestedService NestedService { get; set; }
public RootService(INestedService nestedService)
{
NestedService = nestedService;
}
public void DoSomething()
{
// implement
}
}
public interface INestedService
{
string ConnectionString { get; set; }
void DoSomethingElse();
}
public class NestedService : INestedService
{
public string ConnectionString { get; set; }
public NestedService(string connectionString)
{
ConnectionString = connectionString;
}
public void DoSomethingElse()
{
// implement
}
}
Код: Выделить всё
public HomeController(INestedService nestedService)
{
NestedService = nestedService;
}
Как и ожидалось, я получаю сообщение об ошибке «Невозможно разрешить службу для типа System.String». >
Какие у меня здесь варианты?
Подробнее здесь: https://stackoverflow.com/questions/377 ... resolution