I'm always interested to hear developer opinions about mojoPortal. I don't always agree with them, but I try to keep an open mind and see their perspective. So I monitor the blogosphere with google alerts, so that if anyone mentions mojoPortal in their blog I get an email alert with a link. It doesn't catch everything and more often than not I just get alerts about my own blog posts, but now and then something of interest appears.
So I got an alert about this blog post by Artem Smirnov where he complained about having to inherit from a base class to make a mojoPortal plug in. He wishes he could just use a plain old UserControl and he does not want to have to create any configuration file to install it.
mojoPortal provides a base class, SiteModuleControl which "is a" UserControl that contains some additional functionality that allows you to make multi instance features. Like a blog for example, in mojoPortal you can put an instance of the blog feature on one page and another instance on another page and these are totally separate instances with different content. This is the way most of the features in mojoPortal work and SiteModuleControl provides the instance specific properties and settings that enable easy development of features that support multiple intances.
But maybe sometimes you don't need your feature to support multiple instances and would rather just use a plain old UserControl. This is the valid point I took from Artem's post. And since SiteModuleControl "is a" UserControl and plugs in the same way you plug in a UserControl, I thought, why not make it possible to use a plain old UserControl if you want to. Its a very simple code change to support it, the only thing we do differently if the UserControl is a SiteModuleControl is set a few properties on it, if its just a plain UserControl we skip that step.
Control c = Page.LoadControl(module.ControlSource);
if (c == null) { continue; }
if (c is SiteModuleControl)
{
SiteModuleControl siteModule = c as SiteModuleControl;
siteModule.SiteId = siteSettings.SiteId;
siteModule.ModuleConfiguration = module;
parent.Controls.Add(siteModule);
}
else if(c is UserControl)
{
parent.Controls.Add(c);
}
This change is in svn trunk now. I would also like to mention that you can easily install a SiteModuleControl or a UserControl right from the Web UI, you don't have to create configuration files to install it though there is a system for it and it is recommended if you will be packaging your feature for installation on other machines. The place where you can install it from the UI is under Administration Menu > Advanced Tools > Feature Installation
So, it is now possible to use a plain old UserControl if you want to. If you need to support multiple instances of your feature like we do for most of the mojoPortal features then you should inherit your UserControl from SiteModuleControl and follow the guidelines for feature development.