Overriding a Driver - Is it possible?

Topics: Customizing Orchard, Troubleshooting
Nov 26, 2012 at 9:14 PM

Is it possible to override a driver?

In other words, some module has a driver that has some functionality - a, b, c. I'd like to write my own driver that does some of the functionality - a, c. In my case, b makes assumptions that don't fit my use case.

Can I override a driver or is there a better way? Or must I simply make changes directly to the main driver itself?

Nov 26, 2012 at 9:16 PM

It would help to know the exact scenario but yes, you can use the OrchardSuppressDependency attribute to do that.

Nov 26, 2012 at 9:24 PM
Edited Nov 26, 2012 at 9:26 PM

Ok, sure. For instance - Orchard.Fields.MediaPickerFieldDriver does a check for FileExists:

if (!String.IsNullOrWhiteSpace(field.Url) && !_webSiteFolder.FileExists(field.Url)
updater.AddModelError("Url", T("The media in {0} could not be found",

In my case, the MediaPickerField.Url is a canonical url to Azure Blob storage (https://....). Under the covers, .FileExists assumes that the passed in Url is relative. This causes errors on my Edit screens. 

If there's a module that solves this MediaPicker problem, that'd be ideal. Otherwise, I can try to use OrchardSuppressDependency and write my own Driver that does something a little different. Ideally, the core driver would handle this, but I can contribute back, right? :-)

Nov 26, 2012 at 9:27 PM

It shouldn't. That would be a bug, but I can't seem to be able to reproduce it. Media Picker works just fine for me with blob-stored images.

Nov 26, 2012 at 9:30 PM


Reason #102 to upgrade to 1.6.

I'm on 1.5.1. I just looked at the 1.6 code, and there have been a few changes made. Ok - I'll just hack it up on our instance until we upgrade.