Generic UseCases and UseCaseProvider
hackolein opened this issue · comments
Hello,
is it possible to make the Post Type in the PostUseCase as associatedtype so I write the required method only once:
I started to write the Code, but It dont't work.
Here is the General UseCase in Domain:
public protocol UseCase {
associatedtype E
func many() -> Observable<[E]>
func save(entry: E) -> Observable<Void>
func delete(entry: E) -> Observable<Void>
}
Here is the General UseCaseProvider in Domain:
public protocol UseCaseProvider {
associatedtype U: UseCase
func makeUseCase() -> U
}
Here is the UserCaseProvider in CoreDataPlatform:
public final class PostUseCaseProvider: Domain.UseCaseProvider {
private let coreDataStack = CoreDataStack()
private let postRepository: Repository<Post>
public init() {
postRepository = Repository<Post>(context: coreDataStack.context)
}
public func makeUseCase() -> Domain.UseCase {
return PostsUseCase(repository: postRepository)
}
}
Here get the error Type 'UserCaseProvider' does not conform to protocol 'UseCaseProvider' and Protocol 'UseCase' can only be used as a generic constraint because it has Self or associated type requirements'
Any idea?