Code Monkey home page Code Monkey logo

Comments (10)

yoichitgy avatar yoichitgy commented on June 2, 2024 1

Generated code has something like this:

func resolveInjectablePerson() -> InjectablePerson {
    return self.resolve(PersonType.self)! as! InjectablePerson
}

I think we don't need ! before as!. The generated code can be:

func resolveInjectablePerson() -> InjectablePerson {
    return self.resolve(PersonType.self) as! InjectablePerson
}

from swinject-codegen.

yoichitgy avatar yoichitgy commented on June 2, 2024 1

Generated code has something like this:

func resolveInjectablePerson(foo: AType, bar: BType, baz: String, qux: String) -> InjectablePerson {
    return self.resolve(PersonType.self, arguments: (foo, bar, baz, qux))! as! InjectablePerson
}

I think it's more understandable if the first argument is labeled like this:

func resolveInjectablePerson(foo foo: AType, bar: BType, baz: String, qux: String) -> InjectablePerson {
    return self.resolve(PersonType.self, arguments: (foo, bar, baz, qux))! as! InjectablePerson
}

Then you can use the function like this:

let p = container.resolveInjectablePerson(foo: someFoo, bar: someBar, baz: "some baz", qux: "some qux")

from swinject-codegen.

yoichitgy avatar yoichitgy commented on June 2, 2024 1

Generated code has something like this:

extension Resolvable {
    func registerInjectablePerson(registerClosure: (resolver: ResolverType) -> (InjectablePerson)) -> ServiceEntry<PersonType> {
        return (self as! Container).register(PersonType.self, factory: registerClosure)
    }
}

It uses (self as! Container), which expects the Resolvable instance must be Container type. I think it's more understandable to extend Container type for registration methods. (Resolution methods can stay in the extension of Resolvable.)

from swinject-codegen.

Lutzifer avatar Lutzifer commented on June 2, 2024 1

we can bind the current version to swinject < 2.0.0, then update the generated code, release a new version and depend on swinject >= 2.0.0.
I do not see any necessary migrations, as the code will simply be replaced.

from swinject-codegen.

yoichitgy avatar yoichitgy commented on June 2, 2024

@Lutzifer plz let me know when the code is ready for review.

from swinject-codegen.

Lutzifer avatar Lutzifer commented on June 2, 2024

This can be done, I do not have any open improvements/todos concerning the generated code atm

from swinject-codegen.

yoichitgy avatar yoichitgy commented on June 2, 2024

I'll try reviewing in this weekend.

from swinject-codegen.

yoichitgy avatar yoichitgy commented on June 2, 2024

I wrote three suggestions⬆️ What do you think about them?

from swinject-codegen.

Lutzifer avatar Lutzifer commented on June 2, 2024

we had an issue with (self as! Container) in an earlier version of the code, but it seems to have vanished :-)

from swinject-codegen.

yoichitgy avatar yoichitgy commented on June 2, 2024

@Lutzifer FYI: I'll rename Resolvable to ResolverType in Swinject 2.0.0.

Swinject/Swinject#90
Swinject/Swinject#87

CodeGen also needs migration to Swinject 2.0.0 later, but for now we can work on Swinject 1.x.

from swinject-codegen.

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.