Lowering Entry Point Barriers for Developers

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.

Gravatar Joe Audette is the founder of the mojoPortal project and was the primary developer until February 2017.

Comments

Alan

re: Lowering Entry Point Barriers for Developers

Thursday, October 16, 2008 10:20:59 AM

UserControl c = Page.LoadControl(module.ControlSource) as UserControl;
if (c == null) { continue; }

if (c is SiteModuleControl)
{
SiteModuleControl siteModule = (SiteModuleControl)c;

siteModule.SiteId = siteSettings.SiteId;
siteModule.ModuleConfiguration = module;
}
parent.Controls.Add(c);
 

Alan

re: Lowering Entry Point Barriers for Developers

Thursday, October 16, 2008 10:23:04 AM

Doh, forgot to add a comment:

Same thing, but with 2 lines less of real code, even more if you count brackets! There are also less casts/try-casts ;)

re: Lowering Entry Point Barriers for Developers

Thursday, October 16, 2008 10:29:22 AM

Awlright, I'll go along with that!

Cheers,

Joe

ulu

re: Lowering Entry Point Barriers for Developers

Friday, October 17, 2008 6:07:41 AM

Joe, you are my hero!

re: Lowering Entry Point Barriers for Developers

Friday, October 17, 2008 6:16:00 AM

Thanks ulu!

Your comment just made my day!

Cheers,

Joe

ulu

re: Lowering Entry Point Barriers for Developers

Friday, October 17, 2008 7:49:32 AM

By the way, big thanks for the tip on Google Alerts!

Comments are closed on this post.