Normally in order to get the current document in K13, we must use DI to get the IPageDataContextRetriever
.
However, when trying to register a custom macro field, adding a constructor to my class (in order to use DI) prevents the class from registering:
[assembly: RegisterExtension(typeof(MyMacroFields), typeof(TreeNode))]
public class MyMacroFields : MacroFieldContainer, IService
{
public const string TitleMacro = "MyMetaTitle";
public const string DescriptionMacro = "MyMetaDescription";
private readonly IPageDataContextRetriever _pageDataContextRetriever;
public MyMacroFields(IPageDataContextRetriever pageDataContextRetriever)
{
_pageDataContextRetriever = pageDataContextRetriever;
}
protected override void RegisterFields()
{
base.RegisterFields();
}
}
Is it possible to use DI somehow? Or is there another way to get the current document?
There is a how to article here that solves the issue: