GithubHelp home page GithubHelp logo

Comments (6)

hmlongco avatar hmlongco commented on August 26, 2024 1

Glad you're enjoying Factory. (And the documentation. ;) )

Something similar to this is kicking around over in Resolver, but I'm still not totally convinced of the general need for such a thing. Your associated type and sugar make things type safe, but also makes it a little clunky to setup.

I think I need to kick it around in my head for awhile and see what comes up.

Just noting that your code has a significant problem in that you're storing a factory in an object that belongs to a container. Factory's are designed to be short-lived entities for several reasons, but one of them is that they contain a hard reference to their container so they can resolve when needed.

In short there's a retain cycle there. You may need to consider something like the following with key paths...

    func autoRegister() {
         tag(\MyContainer.processor1, as: pipelineProcessor)
         tag(\MyContainer.processor2, as: pipelineProcessor)
    }

Thanks for the work, regardless.

from factory.

hmlongco avatar hmlongco commented on August 26, 2024 1

Then again, there's this...

extension Container {
    static var processors: [KeyPath<Container, Factory<Processor>>] = [
        \.processor1,
        \.processor2,
    ]

    func processors() -> [Processor] {
        Container.processors.map { self[keyPath: $0]() }
    }

    var processor1: Factory<Processor> { self { Processor(name: "processor #1") } }
    var processor2: Factory<Processor> { self { Processor(name: "processor #2") } }
}

Anyone is also free to add their own extensions and append to the array as needed.

from factory.

DoubleREW avatar DoubleREW commented on August 26, 2024 1

Seems like a really clean and intuitive alternative to a tagging system, thanks.
Maybe you could add this snippet of code to the docs (if it's not already there), I know it's just pure and simple Swift code, but maybe it could point developers coming from other DI frameworks that offer a tagging system in the right direction. Thanks again.

from factory.

hmlongco avatar hmlongco commented on August 26, 2024 1

https://hmlongco.github.io/Factory/documentation/factory/tags/

from factory.

DoubleREW avatar DoubleREW commented on August 26, 2024

Thanks for taking that into consideration.
I've updated the forked repository following your suggestion, the previous poc also leads to an unattended behavior if you tag the factory in its computed variable.

from factory.

hmlongco avatar hmlongco commented on August 26, 2024

I have the code for later consideration should I decide to implement this as a feature in Factory, but for now I think I'll go with the documentation suggestion and see if that covers most of the bases for most of the people.

Thanks for the suggestions.

from factory.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.