Repository navigation
Under the hood
EPiServer decided to filter intercepted properties in 7.5 and intercept only properties included into syncrohinzation process (mapped to db); so EPiInterceptors became useless and I had to
hack replace ContentDataInterceptorHandler with ContentDataInterceptorHandlerExtender class which
allows to configure (using standard IoC configuration):
- Windsor container (I forwarded
EPiPropertiesInterceptor,PropertyInterceptionFilter,IEPiPropertiesRegistrycontracts resolution to service locator to be able to use them in Windsor)
-
ContentDataInterceptorHook- hook which is called once when generating proxy type, to filter out properties we can intercept -
ContentProxyInterceptorSelector- selector, works for each generated proxy instance and selects which interceptor to use.
(outdated)
EPiProperties uses EPiInterceptors package (which extends standard EPiServer ContentDataInterceptor class with possibility to easily add our own custom interception code) and registersEPiPropertiesInterceptorwhich allows developers to easily add properties to content types (pages and blocks) by just implementingIEPiPropertyGetterinterface (see snippet below)
/// <summary>
/// Defines your custom EPi Property get logic.
/// </summary>
public interface IEPiPropertyGetter
{
/// <summary>
/// Detects if the current property can be intercepted by our getter.
/// </summary>
/// <param name="contentData"></param>
/// <param name="property">Property information. </param>
/// <returns>Returns true if the property value will be returned by the GetValue method; otherwise returns false. </returns>
bool CanIntercept(IContentData contentData, PropertyInfo property);
/// <summary>
/// Gets the property value.
/// </summary>
/// <param name="contentData">Page instance. </param>
/// <param name="property">Property information. </param>
/// <returns>Returns the calculated proeprty value</returns>
object GetValue(IContentData contentData, PropertyInfo property);
}
The easiest (but not the only) way to configure EPiPropertiesInterceptor to serve your own properties is implementing initializable module class (don't forget to mark it with [InitializableModule] or [ModuleDependency] attribute, so it will be automatically called by EPiServer initialization engine) inherited from the EPiPropertiesInitializationModuleBase and implement ConfigureEPiProperties method
[InitializableModule]
public class EPiStatusConfigurationModule : EPiPropertiesInitializationModuleBase
{
public override void ConfigureContainer(ServiceConfigurationContext context)
{
context.Container.Configure(x =>
{
x.For<ICmsPageService>().Use<CmsPageService>();
});
}
public override void ConfigureEPiProperties(EPiPropertiesRegistry registry)
{
registry.For<CmsPublishedStatusAttribute>().Use<PublishedStatusPropertyGetter>();
registry.For<CmsPagePredicateAttribute>().Use<PagePredicatePropertyGetter>();
}
}
Configuration is served by EPiPropertiesRegistry class (provides fluent) or simple interface:
public interface IEPiPropertiesRegistry
{
IEnumerable<IEPiPropertyGetter> LookupGetters(PropertyInfo property);
}
both are configured via IoC container:
x.For<EPiPropertiesRegistry>().Singleton().Use<EPiPropertiesRegistry>();
x.For<IEPiPropertiesRegistry>().Use(() => ServiceLocator.Current.GetInstance<EPiPropertiesRegistry>());
Thanks,
Looking forward to getting any feedback on this,
Vladimir