How to use design injection properly swift

79 views Asked by At

We are building a heavy functionality e commerce app. One of the design patterns we are using is design injections . a typical view controller factory method looks like

    public dynamic func leadListingViewController() -> AnyObject {

        return TyphoonDefinition.withFactory(self.leadsStoryBoard(), selector: #selector(UIStoryboard.instantiateViewControllerWithIdentifier(_:)),
                                             parameters: { (factoryMethod) -> Void in
                                                factoryMethod.injectParameterWith("leadListingViewController")

            }, configuration: { (definition) -> Void in

                definition.injectProperty(#selector(CoreAssembly.analyticsLogger), with:self.coreAssembly?.analyticsLogger())
                definition.injectProperty(NSSelectorFromString("leadAssembly"), with:self)
                definition.injectProperty(#selector(CoreAssembly.currentUser), with:self.coreAssembly?.currentUser())
                definition.injectProperty(NSSelectorFromString("applicationAssembly"), with:self.applicationAssembly)
                definition.injectProperty(NSSelectorFromString("managedObjectContext"), with:self.coreAssembly?.managedObjectContext())
                definition.injectProperty(#selector(CoreAssembly.leadFeedStatusOperation), with:self.coreAssembly?.leadFeedStatusOperation())
                definition.injectProperty(#selector(MonetizationAssembly.walletFlowController), with: self.monetizationAssembly?.walletFlowController())
                definition.injectProperty(#selector(LeadAssembly.leadsFlowController), with: self.leadsFlowController()) 
definition.injectProperty(NSSelectorFromString("footerView"), with: self.footerView())      
        })   
    }

Problems Faced:

  1. Now UIViews like footer view are very specific to this view controller and not used anywhere else but still being injected.

  2. Many assemblies have been created and all assembly inject each other making is difficult to comprehend.

  3. Current user is being created in coreAssembly and even when user is not logged in and empty current user is being created.

I would like some tips on how to properly use design injection so I don't face these issues.

0

There are 0 answers