sergdort / CleanArchitectureRxSwift

Example of Clean Architecture of iOS app using RxSwift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Making use cases generic doesn't work with associatedtypes

jbehrens94 opened this issue · comments

Hi! Thanks for providing a really nice starting point to think about how to build up an app and separate concerns. Of course, my first improvement was to have a UsecaseProviding and UsecaseDefinable protocol.

public protocol UsecaseProviding {
    associatedtype Usecase: UsecaseDefinable

    func makeUsecase() -> Usecase
}
public protocol UsecaseDefinable {
    associatedtype DomainEntity

    func entities() -> Observable<[DomainEntity]>
    func save(entity: DomainEntity) -> Observable<Void>
    func delete(entity: DomainEntity) -> Observable<Void>
}

However, as soon as I begin the implementation in the Database target, for example:

public final class PostsUsecaseProvider: UsecaseProviding {
    public typealias Usecase = PostsUsecase<Repository<Post>>
}

I'll get an error like: type alias cannot be declared public, because its underlying type uses an internal type because the Repository types are all internal. As they should be. That's specific logic for the database. However, I do want to have a concrete implementation of the Usecase and UsecaseProvider in the Database target.

The easiest fix would be to just publicize the Repository parts, but that feels kind of dirty. How would you fix this?