Skip to content

Commit

Permalink
Merge pull request #2 from afawcett/master
Browse files Browse the repository at this point in the history
update from Andy's master
  • Loading branch information
ImJohnMDaniel authored Jul 15, 2018
2 parents 3e0b0c9 + 6038ccd commit 64ba686
Show file tree
Hide file tree
Showing 28 changed files with 523 additions and 89 deletions.
3 changes: 3 additions & 0 deletions .execanon
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ try {
}

insert new Widget__c();

RuntimeBindingDemoOrg.run();
RuntimeBindingDemoLocal.run();
89 changes: 89 additions & 0 deletions force-app-1/main/default/classes/RuntimeBindingDemoLocal.cls
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();
}
}
}
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 force-app-1/main/default/classes/RuntimeBindingDemoOrg.cls
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();
}
}
}
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>
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>
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>
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>
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>
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>
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public class AlertCustomerAccountTrigger extends TriggerInjector.TriggerHandler
// Query Contacts
List<Contact> contacts = (List<Contact>)
((TriggerHandlerFieldSetContext) ctx).getRelatedRecordSet(Contact.fields.AccountId);
System.debug('AlertCustomerAccountTrigger');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@
<field>To__c</field>
<value xsi:type="xsd:string">AlertCustomerAccountTrigger</value>
</values>
<values>
<field>Type__c</field>
<value xsi:type="xsd:string">Apex</value>
</values>
</CustomMetadata>
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
<field>To__c</field>
<value xsi:type="xsd:string">c:componentB</value>
</values>
<values>
<field>Type__c</field>
<value xsi:type="xsd:string">LightningComponent</value>
</values>
</CustomMetadata>
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
<field>To__c</field>
<value xsi:type="xsd:string">c:widgetWizard</value>
</values>
<values>
<field>Type__c</field>
<value xsi:type="xsd:string">LightningComponent</value>
</values>
</CustomMetadata>
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public class CheckBalanceAccountTrigger extends TriggerInjector.TriggerHandler {
// Query Contacts
List<Contact> contacts = (List<Contact>)
((TriggerHandlerFieldSetContext) ctx).getRelatedRecordSet(Contact.fields.AccountId);
System.debug('CheckBalanceAccountTrigger');
}
}
6 changes: 3 additions & 3 deletions force-app-3/main/default/classes/ForceApp3Module.cls
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ public class ForceApp3Module extends Module {
public override void configure() {

// Example SObject binding (can be used by trigger frameworks, see force-di-demo-trigger)
bind(Account.getSObjectType()).sequence(20).to(CheckBalanceAccountTrigger.class);
bind(Account.getSObjectType()).apex().sequence(20).to(CheckBalanceAccountTrigger.class);

// Example named binding to a Lightning component
bind('actionWidgetManage').lightningComponent().to('wdigetManager');
bind('lc_actionWidgetManage').lightningComponent().to('c:widgetManager');

// Example named binding to a Visualforce component (via Provider)
bind('layoutWidgetInfo').visualforceComponent().to(WidgetInfoController.Provider.class);
bind('vf_layoutWidgetInfo').visualforceComponent().to(WidgetInfoController.Provider.class);
}
}
2 changes: 1 addition & 1 deletion force-app-3/main/default/classes/WidgetInfoController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ public with sharing class WidgetInfoController {

public ApexPages.StandardController StandardControllerValue {get;set;}

public class BindingProvider implements Binding.Provider {
public class Provider implements Binding.Provider {
public Object newInstance(Object params) {
return new Component.widgetInfo(standardController = (ApexPages.StandardController) params);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@
<field>To__c</field>
<value xsi:type="xsd:string">ForceApp3Module</value>
</values>
<values>
<field>Type__c</field>
<value xsi:type="xsd:string">Module</value>
</values>
</CustomMetadata>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class TriggerInjector {
public static void handle(SObjectType triggerType, TriggerHandlerContext ctx) {
// Discover bindings made against the given sobject type
// (bindings are always returned in sequence if supplied)
List<Binding> bindings = Injector.Default.Bindings.bySObject(triggerType).get();
List<Binding> bindings = Injector.Org.Bindings.bySObject(triggerType).get();
// Construct the handlers
List<TriggerHandler> handlers = new List<TriggerHandler>();
for(Binding binding : bindings) {
Expand Down
Loading

0 comments on commit 64ba686

Please sign in to comment.