Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix of global context #107

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions Source/JSObjectionInjector.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
#import <Foundation/Foundation.h>
#import "JSObjectionModule.h"

@protocol JSObjectionInjectorSelectors

@optional
+ (NSSet *)objectionRequires;
+ (NSDictionary *)objectionRequiresNames;

@end

@interface JSObjectionInjector : NSObject

- (instancetype)initWithContext:(NSDictionary *)theGlobalContext;
- (instancetype)initWithContext:(NSDictionary *)theGlobalContext andModule:(JSObjectionModule *)theModule;
- (instancetype)initWithContext:(NSDictionary *)theGlobalContext andModules:(NSArray *)theModules;
- (instancetype)initWithContext:(NSMutableDictionary *)theGlobalContext;
- (instancetype)initWithContext:(NSMutableDictionary *)theGlobalContext andModule:(JSObjectionModule *)theModule;
- (instancetype)initWithContext:(NSMutableDictionary *)theGlobalContext andModules:(NSArray *)theModules;
- (id)getObject:(id)classOrProtocol;
- (id)getObject:(id)classOrProtocol named:(NSString*)name;
- (id)getObjectWithArgs:(id)classOrProtocol, ... NS_REQUIRES_NIL_TERMINATION;
Expand Down
9 changes: 5 additions & 4 deletions Source/JSObjectionInjector.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ - (void)configure {
@end

@interface JSObjectionInjector() {
NSDictionary *_globalContext;
NSMutableDictionary *_globalContext;
NSMutableDictionary *_context;
NSSet *_eagerSingletons;
NSMutableArray *_modules;
Expand All @@ -43,7 +43,7 @@ - (void)configureModule:(JSObjectionModule *)module;

@implementation JSObjectionInjector

- (instancetype)initWithContext:(NSDictionary *)theGlobalContext {
- (instancetype)initWithContext:(NSMutableDictionary *)theGlobalContext {
if ((self = [super init])) {
_globalContext = theGlobalContext;
_context = [[NSMutableDictionary alloc] init];
Expand All @@ -55,15 +55,15 @@ - (instancetype)initWithContext:(NSDictionary *)theGlobalContext {
return self;
}

- (instancetype)initWithContext:(NSDictionary *)theGlobalContext andModule:(JSObjectionModule *)theModule {
- (instancetype)initWithContext:(NSMutableDictionary *)theGlobalContext andModule:(JSObjectionModule *)theModule {
if ((self = [self initWithContext:theGlobalContext])) {
[self configureModule:theModule];
[self initializeEagerSingletons];
}
return self;
}

- (instancetype)initWithContext:(NSDictionary *)theGlobalContext andModules:(NSArray *)theModules {
- (instancetype)initWithContext:(NSMutableDictionary *)theGlobalContext andModules:(NSArray *)theModules {
if ((self = [self initWithContext:theGlobalContext])) {
for (JSObjectionModule *module in theModules) {
[self configureModule:module];
Expand Down Expand Up @@ -261,6 +261,7 @@ - (void)configureModule:(JSObjectionModule *)module {
NSSet *mergedSet = [module.eagerSingletons setByAddingObjectsFromSet:_eagerSingletons];
_eagerSingletons = mergedSet;
[_context addEntriesFromDictionary:module.bindings];
[_globalContext addEntriesFromDictionary:_context];
}

- (void)configureDefaultModule {
Expand Down