-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from afawcett/master
update from Andy's master
- Loading branch information
Showing
28 changed files
with
523 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,6 @@ try { | |
} | ||
|
||
insert new Widget__c(); | ||
|
||
RuntimeBindingDemoOrg.run(); | ||
RuntimeBindingDemoLocal.run(); |
89 changes: 89 additions & 0 deletions
89
force-app-1/main/default/classes/RuntimeBindingDemoLocal.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* Demonstration of local code configured bindings | ||
**/ | ||
public class RuntimeBindingDemoLocal { | ||
|
||
/** | ||
* This application has two dependencies defined as follows | ||
**/ | ||
public interface Display { | ||
String say(Message message); | ||
} | ||
public abstract class Message { | ||
public abstract String saySomething(); | ||
} | ||
|
||
/** | ||
* The application outputs a message to the user | ||
**/ | ||
public class WelcomeApp { | ||
|
||
private Message message; | ||
private Display display; | ||
|
||
public WelcomeApp(Injector injector) { | ||
|
||
// Inject dependences based on the given injector | ||
message = (Message) injector.getInstance(Message.class); | ||
display = (Display) injector.getInstance(Display.class); | ||
} | ||
|
||
public String greetings() { | ||
return display.say(message); | ||
} | ||
} | ||
|
||
/** | ||
* This example uses purely runtime binding configuration | ||
**/ | ||
public static void run() { | ||
|
||
// Configure the apps dependencies | ||
Injector injector = configureBindings(); | ||
|
||
// Run the app! | ||
WelcomeApp welcomeApp = new WelcomeApp(injector); | ||
System.debug(welcomeApp.greetings()); | ||
} | ||
|
||
/** | ||
* The applications dependencies are configured dynamically via the above Injector | ||
**/ | ||
public static Injector configureBindings() { | ||
|
||
// Vary Message and Display implementations depending on the users out of office | ||
return | ||
new Injector( | ||
UserAvailability__c.getInstance().OutOfOffice__c ? | ||
new Module() | ||
.bind(Message.class).to(Weekday.class) | ||
.bind(Display.class).to(BeAwesome.class) : | ||
new Module() | ||
.bind(Message.class).to(Weekend.class) | ||
.bind(Display.class).to(Fun.class)); | ||
} | ||
|
||
/** | ||
* The WelcomeApp class is unware of the specific implementations | ||
**/ | ||
public class Weekday extends Message { | ||
public override String saySomething() { | ||
return 'Have a good day at work!'; | ||
} | ||
} | ||
public class Weekend extends Message { | ||
public override String saySomething() { | ||
return 'Have a great weelend!'; | ||
} | ||
} | ||
public class BeAwesome implements Display { | ||
public String say(Message message) { | ||
return 'Go be awesome! ' + message.saySomething(); | ||
} | ||
} | ||
public class Fun implements Display { | ||
public String say(Message message) { | ||
return 'Party time! ' + message.saySomething(); | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
force-app-1/main/default/classes/RuntimeBindingDemoLocal.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="urn:metadata.tooling.soap.sforce.com" fqn="RuntimeBindingDemoLocal"> | ||
<apiVersion>43.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
83 changes: 83 additions & 0 deletions
83
force-app-1/main/default/classes/RuntimeBindingDemoOrg.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* Demonstration of org level code configured bindings | ||
**/ | ||
public class RuntimeBindingDemoOrg { | ||
|
||
/** | ||
* This application has two dependencies defined as follows | ||
**/ | ||
public interface Display { | ||
String say(Message message); | ||
} | ||
public abstract class Message { | ||
public abstract String saySomething(); | ||
} | ||
|
||
/** | ||
* The application outputs a message to the user | ||
**/ | ||
public class WelcomeApp { | ||
|
||
// Inject dependences via org level injector | ||
private Message message = (Message) Injector.Org.getInstance(Message.class); | ||
private Display display = (Display) Injector.Org.getInstance(Display.class); | ||
|
||
public String greetings() { | ||
return display.say(message); | ||
} | ||
} | ||
|
||
/** | ||
* This example uses purely runtime binding configuration | ||
**/ | ||
public static void run() { | ||
|
||
// Run the app! | ||
WelcomeApp welcomeApp = new WelcomeApp(); | ||
System.debug(welcomeApp.greetings()); | ||
} | ||
|
||
/** | ||
* This class to configure the bindings is injected into the Injector.Org instance via Binding__mdt | ||
**/ | ||
public class WelcomeAppBindings extends Module { | ||
|
||
/** | ||
* Org level bindings are also visible to the c:injector Visualforce and Lightning components | ||
**/ | ||
public override void configure() { | ||
// Vary Message and Display implementations depending on the users out of office | ||
if (UserAvailability__c.getInstance().OutOfOffice__c) { | ||
bind(Message.class).to(Weekday.class); | ||
bind(Display.class).to(BeAwesome.class); | ||
} else { | ||
bind(Message.class).to(Weekend.class); | ||
bind(Display.class).to(Fun.class); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* The WelcomeApp class is unware of the specific implementations | ||
**/ | ||
public class Weekday extends Message { | ||
public override String saySomething() { | ||
return 'Have a good day at work!'; | ||
} | ||
} | ||
public class Weekend extends Message { | ||
public override String saySomething() { | ||
return 'Have a great weelend!'; | ||
} | ||
} | ||
public class BeAwesome implements Display { | ||
public String say(Message message) { | ||
return 'Go be awesome! ' + message.saySomething(); | ||
} | ||
} | ||
public class Fun implements Display { | ||
public String say(Message message) { | ||
return 'Party time! ' + message.saySomething(); | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
force-app-1/main/default/classes/RuntimeBindingDemoOrg.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="urn:metadata.tooling.soap.sforce.com" fqn="RuntimeBindingDemoOrg"> | ||
<apiVersion>43.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
21 changes: 21 additions & 0 deletions
21
force-app-1/main/default/customMetadata/Binding.apex_RuntimeBindingDemoModule.md-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<CustomMetadata xmlns="http://soap.sforce.com/2006/04/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | ||
<label>Runtime Binding Demo Org</label> | ||
<protected>false</protected> | ||
<values> | ||
<field>BindingObject__c</field> | ||
<value xsi:nil="true"/> | ||
</values> | ||
<values> | ||
<field>BindingSequence__c</field> | ||
<value xsi:nil="true"/> | ||
</values> | ||
<values> | ||
<field>To__c</field> | ||
<value xsi:type="xsd:string">RuntimeBindingDemoOrg.WelcomeAppBindings</value> | ||
</values> | ||
<values> | ||
<field>Type__c</field> | ||
<value xsi:type="xsd:string">Module</value> | ||
</values> | ||
</CustomMetadata> |
5 changes: 5 additions & 0 deletions
5
...ult/objectTranslations/UserAvailability__c-en_US/OutOfOffice__c.fieldTranslation-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<CustomFieldTranslation xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<label><!-- Out Of Office --></label> | ||
<name>OutOfOffice__c</name> | ||
</CustomFieldTranslation> |
12 changes: 12 additions & 0 deletions
12
...anslations/UserAvailability__c-en_US/UserAvailability__c-en_US.objectTranslation-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<CustomObjectTranslation xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<caseValues> | ||
<plural>false</plural> | ||
<value>User Availability</value> | ||
</caseValues> | ||
<caseValues> | ||
<plural>true</plural> | ||
<value>Out of Office</value> | ||
</caseValues> | ||
<startsWith>Consonant</startsWith> | ||
</CustomObjectTranslation> |
7 changes: 7 additions & 0 deletions
7
force-app-1/main/default/objects/UserAvailability__c/UserAvailability__c.object-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<customSettingsType>Hierarchy</customSettingsType> | ||
<enableFeeds>false</enableFeeds> | ||
<label>User Availability</label> | ||
<visibility>Public</visibility> | ||
</CustomObject> |
9 changes: 9 additions & 0 deletions
9
force-app-1/main/default/objects/UserAvailability__c/fields/OutOfOffice__c.field-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<fullName>OutOfOffice__c</fullName> | ||
<defaultValue>false</defaultValue> | ||
<externalId>false</externalId> | ||
<label>Out Of Office</label> | ||
<trackTrending>false</trackTrending> | ||
<type>Checkbox</type> | ||
</CustomField> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.