Simpleinjector: The Configuration is invalid. The type is directly or Indirectly Depending on itself

Asked

Viewed 392 times

1

I have the following problem when applying the Simpleinjector container in a simple application:

The configuration is invalid. 
The type BookAppService is directly or indirectly depending on itself. 
The cyclic graph contains the following types: BookAppService -> BookAppService -> BookAppService.

This is the Bookappservice class:

public class BookAppService : AppServiceBase<Book>, IBookAppService
{
    private readonly IBookAppService _bookService;

    public BookAppService(IBookAppService bookService) : base(bookService)
    {
        _bookService = bookService;
    }

    public IEnumerable<Book> GetSpecialBooks(IEnumerable<Book> books)
    {
        return _bookService.GetSpecialBooks(_bookService.GetAll());
    }

And this is the configuration of the Simpleinjectorinitializer:

container.Register(typeof(IAppServiceBase<>), typeof(AppServiceBase<>));
container.Register<IBookAppService, BookAppService>(Lifestyle.Scoped);

I am very beginner in Ioc and DI, and thank you for any help and tip. Thank you.

  • You need to put AppServiceBase<> and IBookAppService ...

1 answer

1


The problem is you’re asking for an instance of BookAppService within an instance of itself, causing infinite recursion.

This doesn’t make much sense, you can access the current instance using the this and the AppServiceBase inherited using base.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.