In UBIK® 4, there is a mechanism for the automatic detection of changes by other UBIK® processes, which provide notifications for their changes.
Configuration
The UBIKContent web service can be configured to react to such notifications by updating its cache; mostly the user group cache used for rights evaluation.
Change detection can be configured in the application settings of the UBIKContent web service.
Customizing
There are multiple possibilities to react to change detections via customizing.
Overriding the event handler of an instance
protected virtual void OnBeforeUpdateByChangeNotification()
{
// Called before an already cached instance will be reloaded from the database because of a change notification.
}
protected virtual void OnAfterUpdateByChangeNotification()
{
// Called after an instance was reloaded from the database because of a change notification.
}
{
// Called before an already cached instance will be reloaded from the database because of a change notification.
}
protected virtual void OnAfterUpdateByChangeNotification()
{
// Called after an instance was reloaded from the database because of a change notification.
}
Attaching a new event handler to the UBIKEventManager
// In Plugin code or custom code library, or anywhere else:
UBIK.Kernel.UbikEventManager eventMan = Environment.GetEventManager();
eventMan.InstanceAfterUpdateByChangeNotification += EventMan_InstanceAfterUpdateByChangeNotification;
eventMan.InstanceBeforeUpdateByChangeNotification += EventMan_InstanceBeforeUpdateByChangeNotification;
// Don't forget to unregister from the events when the handlers are not needed anymore, to avoid a memory leak:
// eventMan.InstanceAfterUpdateByChangeNotification -= EventMan_InstanceAfterUpdateByChangeNotification;
// eventMan.InstanceBeforeUpdateByChangeNotification -= EventMan_InstanceBeforeUpdateByChangeNotification;
// ...
private void EventMan_InstanceBeforeUpdateByChangeNotification(BaseClass sender)
{
// Act before imminent reload, for example:
// InvalidateState(sender);
}
private void EventMan_InstanceAfterUpdateByChangeNotification(BaseClass sender)
{
// React to change, for example:
// UpdateCache(sender);
}
UBIK.Kernel.UbikEventManager eventMan = Environment.GetEventManager();
eventMan.InstanceAfterUpdateByChangeNotification += EventMan_InstanceAfterUpdateByChangeNotification;
eventMan.InstanceBeforeUpdateByChangeNotification += EventMan_InstanceBeforeUpdateByChangeNotification;
// Don't forget to unregister from the events when the handlers are not needed anymore, to avoid a memory leak:
// eventMan.InstanceAfterUpdateByChangeNotification -= EventMan_InstanceAfterUpdateByChangeNotification;
// eventMan.InstanceBeforeUpdateByChangeNotification -= EventMan_InstanceBeforeUpdateByChangeNotification;
// ...
private void EventMan_InstanceBeforeUpdateByChangeNotification(BaseClass sender)
{
// Act before imminent reload, for example:
// InvalidateState(sender);
}
private void EventMan_InstanceAfterUpdateByChangeNotification(BaseClass sender)
{
// React to change, for example:
// UpdateCache(sender);
}