This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
MSActiveConfig Instantiation
Javier Soto edited this page Jul 7, 2013
·
11 revisions
This is what creating the MSActiveConfig
object with its dependencies would look like:
#import <MSActiveConfig/MSActiveConfig.h>
#import <MSActiveConfig/MSJSONURLRequestActiveConfigDownloader.h>
#import <MSActiveConfig/MSUserDefaultsActiveConfigStore.h>
#import <MSActiveConfig/MSActiveConfigConfigurationState.h>
#import <MSActiveConfig/MSActiveConfigConfigurationState+MSLazyLoadedState.h>
- (MSActiveConfigConfigurationState *)initialActiveConfigState
{
NSString *bootstrappedActiveConfigFileName = @"InitialActiveConfig.json";
NSString *bootstrappedActiveConfigFilePath = [[NSBundle mainBundle] pathForResource:bootstrappedActiveConfigFileName ofType:nil];
return [MSActiveConfigConfigurationState lazyLoadedConfigurationStateFromJSONFileAtPath:bootstrappedActiveConfigFilePath];
}
- (MSActiveConfig *)newActiveConfig
{
// Config Downloader
MSJSONURLRequestActiveConfigDownloader *downloader = [[MSJSONURLRequestActiveConfigDownloader alloc] initWithCreateRequestBlock:^NSURLRequest *(NSString *userID) {
return [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://myserver.com/activeconfig/user/%@", userID]]];
}];
// Config Store
MSActiveConfigConfigurationState *initialConfigurationState = [self initialActiveConfigState];
MSUserDefaultsActiveConfigStore *configStore = [[MSUserDefaultsActiveConfigStore alloc] initWithInitialSharedConfiguration:initialConfigurationState];
// Active Config
MSActiveConfig *activeConfig = [[MSActiveConfig alloc] initWithConfigDownloader:configDownloader
configStore:configStore];
return activeConfig;
}