Quantcast
Channel: C1 CMS Foundation - Open Source on .NET
Viewing all articles
Browse latest Browse all 2540

New Post: Event subscriptions - best practices

$
0
0

OK. It worked. the code:

	[ApplicationStartup]publicclass TestStartupEvents
	{static TestStartupEvents()
		{//RegisterEvents();return;
		}publicstaticvoid OnBeforeInitialize()
		{//RegisterEvents();return;
		}publicstaticvoid OnInitialized()
		{
			RegisterEvents();return;
		}publicstaticvoid RegisterEvents()
		{
			DataEvents<IPage>.OnAfterAdd += new DataEventHandler(DataEvents_OnAferAdd);
			DataEvents<IPage>.OnDeleted += new DataEventHandler(DataEvents_OnDeleted);
			DataEvents<IPage>.OnNew += new DataEventHandler(DataEvents_OnNew);
			DataEvents<IPage>.OnStoreChanged += new StoreEventHandler(DataEvents_OnStoreChanged);return;
		}///<summary>///</summary>///<returns></returns>staticvoid DataEvents_OnAferAdd(object sender, DataEventArgs dataEventArgs)
		{// here a minor update to the cache could be done (like adding info about the new element only).return;
		}staticvoid DataEvents_OnNew(object sender, DataEventArgs dataEventArgs)
		{// here a minor update to the cache could be done // (like adding info about the new element only).return;
		}staticvoid DataEvents_OnDeleted(object sender, DataEventArgs dataEventArgs)
		{// here a minor update to the cache could be done // (like adding info about the new element only).return;
		}staticvoid DataEvents_OnStoreChanged(object sender, StoreEventArgs storeEventArgs)
		{if (!storeEventArgs.DataEventsFired)
			{// an external update event happened - DataEvents_OnBeforeAdd not fired// here a complete cache flush could be done
			}return;
		}
	}
}

Another question: hooking events can be done in Globa.asax too. Right?
OK this approach is more elegant, but Global.asax Application_Start should do the job?

thanks

mel 


Viewing all articles
Browse latest Browse all 2540

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>