Git Product home page Git Product logo

Comments (10)

jdewind avatar jdewind commented on August 23, 2024

I'd like to keep Objection's interface simple if I can. What kind of situation were you thinking of using this feature for?

from objection.

Undistraction avatar Undistraction commented on August 23, 2024

It seems to me to be a fairly fundamental requirement to be honest. Some classes are used in many different places or with an application in different states, and without optional injection points this becomes limited. A class might be designed to have a dependency satisfied either when it is created or later during application flow. Or it might only be satisfied once a user has performed some action, for example I might instantiate a class using an injector every time my application is run. maybe the first few times it is run one of its dependencies is missing because a user hasn't filled out some details, but later on, after the use has filled out details, when the application initialises, that dependency is present and injected. I think this is a fundamental feature for making Objection more flexible. So far as the API goes I think this wouldn't involve many changes. You would just need a way for a dependency to be declared as optional. Changes behind the API would be another matter of course, but I think I can see how it could be done without too much fuss.

from objection.

jdewind avatar jdewind commented on August 23, 2024

Interesting,

Objection does provide a default instance if it is a class requirement. So this would be something needed for a protocol binding, correct?

from objection.

Undistraction avatar Undistraction commented on August 23, 2024

Please can you clarify what you mean by 'Objection does provide a default instance if it is a class requirement'?

from objection.

jdewind avatar jdewind commented on August 23, 2024

The only time Objection throws an exception is if an object requires a dependency where the interface is not a class but rather a protocol.

@interface MyClass
@property (nonatomic, retain) id<AProtocol> object // Objection throws if a binding was not created
@property (nonatomic, retain) AnotherClass object2 // if AnotherClass is not registered. Objection will register it and provide an instance of it
@end

from objection.

Undistraction avatar Undistraction commented on August 23, 2024

Ah. I hadn't noticed that. In fact I think this would be another good way of using an annotation and is tied into optional dependencies. Perhaps every dependency should support annotation with 'optional' and 'auto'. I would expect to be able to decide firstly if a dependency is optional and secondly if it isn't optional, whether Objection should satisfy it automatically. Satisfying a dependency automatically is a little confusing as a default I think. Perhaps I was planning on mapping a particular preconfigured instance of a class to a dependency but forgot. Now it will be confusing for me to see what is wrong as the dependency will have been satisfied, but not with the instance I was wanted to use.

from objection.

jdewind avatar jdewind commented on August 23, 2024

Agreed,

In order to support optional dependencies Objection would have to by default:

  • Throw regardless of whether it is a protocol or class -- be consistent
  • Suppress errors if the dependency is optional -- nil isn't an error so I dont see a need for providing a default instance.

from objection.

Undistraction avatar Undistraction commented on August 23, 2024

Absolutely. Even without optional dependencies I think it is important to throw whether protocol or class, but I really think optional dependencies would be a really nice addition.

from objection.

jdewind avatar jdewind commented on August 23, 2024

I'll enqueue this feature request along with issues #11 and #9. Hopefully
we'll have something by next week.

from objection.

Undistraction avatar Undistraction commented on August 23, 2024

That's great. If you are interested I've added a few simple methods to your JSObjection.h API here: https://github.com/1ndivisible/objection/blob/master/Source/JSObjection.m. Also found it very easy to make everything work within a single context by making a couple of chnages here: https://github.com/1ndivisible/objection/blob/master/Source/JSObjectionInjector.m by 1. passing bindings straight to the global context. 2. Removing a small block of functionality in getObject. Seems to be working fine. Might be worth considering implementing a way of choosing between a global mode and a separated injectors mode? Updated your tests to cover these changes I think.

from objection.

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.