Skip to main content
Version: v12.x - Umbraco 12

Dependencies

Whenever uSync.Complete attempts to push, pull or export items from an Umbraco site, it will perform a set of dependency checks against the items to be used. It does this to see what else is needed to make an item exist on another Umbraco site.

For a content item these dependencies might include:

  • Media used in the content item,
  • The doctype used to create the content item,
  • The datatypes within the doctype,
  • The template used for the content item,
  • Any culture and host name settings for the content item,
  • Any public access security settings associated with the item.

In order to calculate these dependencies uSync.Complete will consult a list of dependency checkers to see what dependencies are needed for an item.

uSyncDependency

To include a dependency checker you need to write a class that implements the uSyncDependency interface.

public interface ISyncDependencyChecker<TObject> : ISyncDependencyItem
{
IEnumerable<uSyncDependency> GetDependencies(TObject item, DependencyFlags flags);
}

GetDependencies

The GetDependencies method must return a list of dependencies for a given item. At the very least this should include the item passed.

As an example the dependency checker for language items in Umbraco looks like this:

public class LanguageChecker : ISyncDependencyChecker<ILanguage>
{
public UmbracoObjectTypes ObjectType => UmbracoObjectTypes.Language;

public IEnumerable<uSyncDependency> GetDependencies(ILanguage item, DependencyFlags flags)
{
if (item == null) return Enumerable.Empty<uSyncDependency>();

return new uSyncDependency
{
Name = item.CultureName,
Udi = item.GetUdi(),
Order = DependencyOrders.Languages,
Flags = DependencyFlags.None,
Level = 0
}.AsEnumerableOfOne();
}

}

Any GetDependencies method will be called for all items of TObject that uSync encounters

DependencyFlags

Whenever the GetDependencies method is called a set of DependencyFlags will be passed, these flags can be used to alter what is included as part of any sync.

public enum DependencyFlags
{
None = 0,
IncludeChildren = 2,
IncludeAncestors = 4,
IncludeDependencies = 8,
IncludeViews = 16,
IncludeMedia = 32,
IncludeLinked = 64,
IncludeMediaFiles = 128,
IncludeConfig = 256,
AdjacentOnly = 512,
RootSync = 1024,
IncludeContents = 2048
}

The most common flags are:

FlagNote
IncludeChildrenInclude any children of this item in the sync.
IncludeAncestorsInclude the parents of this item in the sync.
IncludeDependenciesInclude any settings needed for this item (e.g doctypes, datatypes, etc).
IncludeViewsInclude any template/files needed for an item.
IncludeMediaInclude any media linked to within an item.
IncludeLinkedInclude any linked items (e.g content linked via a content picker).
AdjacentOnlyInclude only the direct descendants/parents of this item.

The other flags are used, but usually don't have a baring on how a dependency checker performs (e.g includeMediaFiles is used later on in the exporter process to say if the resulting sync pack should include the physical media for an item).