square / Cleanse

Lightweight Swift Dependency Injection Framework
Other
1.78k stars 90 forks source link

Readme is out-of-date #109

Closed mcmurrym closed 5 years ago

mcmurrym commented 5 years ago

I am trying to learn and understand the Clean framework. The sample project is nice but not as detailed in explanations as the Readme. When I try to follow the Readme however, it doesn't work; it appears to be out-of-date. I would be happy to update it, but I don't understand the framework enough yet to do so.

sebastianv1 commented 5 years ago

@mcmurrym You're correct that the README is a little bit out of date, we're currently in the process of updating its contents. Do you mind pointing out the parts that are confusing so that we can address them in the next revision?

mcmurrym commented 5 years ago

The text seems fine, not really confusing, but sample code isn't working well. for example:

extension UIWindow {
  struct Module : Cleanse.Module {
    public func configure(binder: Binder<Singleton>) {
      binder
        .bind(UIWindow.self)
        .sharedInScope()
        .to { (rootViewController: TaggedProvider<UIViewController.Root>) in
          let window = UIWindow(frame: UIScreen.mainScreen().bounds)
          window.rootViewController = rootViewController.get()
          return window
        }
    }
  }

complains about Singleton

And binder.install(module: UIWindow.Module.self) is incorrect, I think the replacement is include but am unsure.

This snippet produces several errors:

extension RootViewController {
    /// Configures RootViewController
    struct Module : Cleanse.Module {
        func configure<B : Binder>(binder binder: B) {
            // Configures the RootViewController to be provided by the initializer
            binder
                .bind(RootViewController.self)
                .to(factory: RootViewController.init)

            // This satisfies UIWindow depending on TaggedProvider<UIViewController.Root>
            // The actual root is our RootViewController wrapped in a UINavigationController
            binder
                .bind(UIViewController.self)
                .tagged(with: UIViewController.Root.self)
                .to { UINavigationController(rootViewController: $0 as RootViewController) }
        }
    }
}
sebastianv1 commented 5 years ago

I've opened #110 to update the sample project (and included an additional CI stage to keep the sample project building).

What errors are you getting for the snippet you attached?

HenriLangenhoven commented 5 years ago

Hi guys. The code snippets in the Readme still mention binder.install(module:) in several places.

sebastianv1 commented 5 years ago

I've merged #111 to hopefully address all of your issues with the README.