| ProfileSitecore APIBlogLists | Help |
|
December 05 Pluggable DataEngine?Recently, we had a question on plugging a custom DataEngine into Sitecore:
While the DataEngine itself is not pluggable, the individual commands making up the engine is. That allows you to override any command in the engine. To illustrate what the engine actually does, here is the code for DataEngine.GetItem:
public Item GetItem(ID itemId, Language language, Version version) {
GetItemCommand command = Commands.GetItemPrototype.Clone(); command.Initialize(itemId, language, version);
return command.Execute();
} All methods look like this (with different command prototypes).
To override the behaviour of the GetItemCommand, all you need to do is to assign your own class to the GetItemPrototype property. In V5.3, you have to do this in code (in a hook, for instance). In V5.3.1 you will be able to do it directly from web.config.
For the hook, you can use something like this:
public class MyHook : IHook {
#region IHook implementation
public void Initialize() {
Database database = Factory.GetDatabase("master"); database.Engines.DataEngine.Commands.GetItemPrototype = new MyGetItemCommand(); } #endregion
} Set up the hook in web.config like this: <hooks>
<hook type="MyNamespace.MyHook, MyAssembly"/> ... </hooks> The command implementation should look something like this:
public class MyGetItemCommand : GetItemCommand {
protected override Item DoExecute() {
// Do your stuff here and return an item or null. // Optionally, you can call base.DoExecute(); } public override GetItemCommand Clone() {
MyGetItemCommand command = new MyGetItemCommand(); command.Engine = Engine;
return command;
} } There is a number of other methods you can override, but DoExecute is the one that does the actual work.
Note that if you override any of the event generating commands (such as SaveItem), the events will still be fired. If you wish to take over the event handling, you should also override the CanExecute and Executed methods.
Also, note that no security checking is performed at this level. The DataEngine is called from the ItemProvider (via ItemManager) which handles securit. If you wish to alter the way security is applied, this might be a better place to hook in (which can be done by using the ItemManager.Provider property).
Comments (4)
TrackbacksThe trackback URL for this entry is: http://sitecore.spaces.live.com/blog/cns!E2F0554546F0A020!162.trak Weblogs that reference this entry
|
|
|