Comments (10)
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.
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.
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.
Please can you clarify what you mean by 'Objection does provide a default instance if it is a class requirement'?
from objection.
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.
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.
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.
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.
I'll enqueue this feature request along with issues #11 and #9. Hopefully
we'll have something by next week.
from objection.
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)
- Support setting properties of non-object types
- Does objection inject dependencies automatically on creation? HOT 2
- frida ๅฝไปค้่ฏฏ
- Compatibility with Swift HOT 3
- Reseting Objection's global context storage caches HOT 2
- Injection at Initialization HOT 3
- Inject property declared in a category.
- Sharing singleton scope when deriving a new injector HOT 1
- Ability to specify override objects HOT 5
- @objection_initializer not passing arguments HOT 2
- Injecting object with protocol and superclass
- about sample? HOT 1
- why not use modern objective-c
- Why "JSObjectionModule.m" file line fifth to write "#import <Objection/JSObjectionProviderEntry.h>", but not "#import "JSObjectionProviderEntry.h"".
- why JSObjectionEntry's injector property is "assign" not "weak"?
- Passing nil arguments for get objection object HOT 7
- inScope:JSObjectionScopeSingleton doesn't work since Cocoapods version 1.6 HOT 19
- Build is broken on XCode 6.4 HOT 4
- Getting a reference to the JSObjectionInjector which created an object? HOT 2
- Undeclared selector warnings
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from objection.