Assuming there are classes as follow.
interface Book {
Guid Id { get; }
Guid AuthorId { get; }
}
interface Author {
Guid Id { get; }
void Autograph();
}
Then there are service and data store
interface AutographService {
void Sign(Guid bookId);
}
interface BookStore {
Book GetBookById(Guid bookId);
}
Given that the entry point is to call AutographService.Sign(bookId)
, there are BookStore
and AuthorStore
injected into AutographService
. Does the following data store violate Dependency Inversion Principle?
interface AuthorStore {
Author GetAuthorById(Guid authorId);
}
And how about the following instead?
interface AuthorStore {
Author GetAuthorByBookId(Guid bookId);
}
As Dependency inversion principle states:
Let's see these principles more carefully according your code snippets.
You are using interfaces. And interface is an abstraction. It is not concrete implementation. So you are okay with this state.
As your abstraction AuthorStore
implements interface interface AuthorStore
and you are injecting this abstraction into your service. So it can be concluded that this principle is complied.