The WFFM module was significantly re-written in version 8.1+ and allows configuration driven dependency injection out of the box.
For example, if you take a look at the /sitecore/system/Modules/Web Forms for Marketers/Settings/Actions/Save Actions/Update Contact Details
Save Action then you will see the following item definition:
Factory Object Name: /sitecore/wffm/actions/updateContactDetails
Assembly: [Empty]
Class: [Empty]
MVC Type: [Empty]
Note that the Factory Object Name
field is new and in previous versions the other 3 fields would be filled in with the assembly details of the Save Action. Instead, in the latest versions in Sitecore.WFFM.Dependencies.config you will find the following definition:
<wffm>
<actions>
...
<updateContactDetails type="Sitecore.WFFM.Actions.SaveActions.UpdateContactDetails, Sitecore.WFFM.Actions">
<param name="analyticsTracker" ref="/sitecore/wffm/analytics/analyticsTracker" />
<param name="authentificationManager" ref="/sitecore/wffm/authentificationManager" />
<param name="logger" ref="/sitecore/wffm/logger" />
<param name="facetFactory" ref="/sitecore/wffm/analytics/facetFactory" />
<param name="contactManager" ref="/sitecore/wffm/analytics/contactManager" />
</updateContactDetails>
...
</actions>
<logger type="Sitecore.Forms.Core.Dependencies.DefaultImplLogger, Sitecore.Forms.Core"/>
<authentificationManager type="Sitecore.Forms.Core.Dependencies.DefaultImplAuthentificationManager, Sitecore.Forms.Core"/>
<analytics>
<analyticsTracker type="Sitecore.WFFM.Analytics.Dependencies.DefaultImplAnalyticsTracker, Sitecore.WFFM.Analytics"/>
<facetFactory type="Sitecore.WFFM.Analytics.Dependencies.DefaultImplFacetFactory, Sitecore.WFFM.Analytics"/>
<contactManager type="Sitecore.WFFM.Analytics.Dependencies.ContactManagerWrapper, Sitecore.WFFM.Analytics">
<param name="contactManager" ref="/sitecore/tracking/contactManager" />
</contactManager>
...
</analytics>
</wffm>
The Save Action accepts these settings as Constructor parameters, the params
defined in config must match those in your code. These will all be wired up automatically by the module.
public class UpdateContactDetails : WffmSaveAction
{
private readonly IAnalyticsTracker analyticsTracker;
private readonly IAuthentificationManager authentificationManager;
private readonly ILogger logger;
private readonly IFacetFactory facetFactory;
private readonly IContactManager contactManager;
public string Mapping { get; set; }
public UpdateContactDetails(IAnalyticsTracker analyticsTracker, IAuthentificationManager authentificationManager, ILogger logger, IFacetFactory facetFactory, IContactManager contactManager)
{
Assert.IsNotNull((object) analyticsTracker, "analyticsTracker");
...
this.analyticsTracker = analyticsTracker;
this.authentificationManager = authentificationManager;
this.logger = logger;
this.facetFactory = facetFactory;
this.contactManager = contactManager;
}
public override void Execute(ID formId, AdaptedResultList adaptedFields, ActionCallContext actionCallContext = null, params object[] data)
{
this.UpdateContact(adaptedFields);
}
...
}