New provider model for BlogEngine

Apr 10, 2007

BlogEngine.NET runs entirely on XML files located in the App_Data folder. That makes it truly plug ‘n play, but not everybody likes XML files. We’ve had a lot of requests for SQL Server and MySql providers, so now we finally released an open provider model.

Now it’s possible to write your own providers in an extremely easy and intuitive way. There are two steps involved. First of all you need to write the provider and secondly you have to add it to the web.config.

Writing providers

A provider is 1 single class that inherits from BlogProvider and implements 10 methods. These methods inserts, updates, deletes and retrieves posts, pages and categories. Here are the abstract methods that must be implemented on the custom provider:

// Post
public abstract Post SelectPost(Guid id);
public abstract void InsertPost(Post post);
public abstract void UpdatePost(Post post);
public abstract void DeletePost(Post post);

// Page
public abstract Page SelectPage(Guid id);
public abstract void InsertPage(Page page);
public abstract void UpdatePage(Page page);
public abstract void DeletePage(Page page);

// Category
public abstract CategoryDictionary LoadCategories();
public abstract void SaveCategories(CategoryDictionary categories);

When they are implemented you can fill them with SQL statements, stored procedures or whatever data store mechanisms you like. You can look at the default XmlBlogProvider for inspiration.

Changing web.config

The BlogEngine configuration section in web.config needs to be updated to make the custom provider work. This is the section with the default XML provider set up. Just add your provider and set it as default in the defaultProvider attribute.

< BlogEngine >
 < blogProvider defaultProvider ="XmlBlogProvider" >
  < providers >
   < add name ="XmlBlogProvider" type ="DotNetSlave.BlogEngine.BusinessLogic.XmlBlogProvider" />
  </ providers >
 </ blogProvider >
</ BlogEngine >

When both the provider is written and web.config changed, it will work just like that. If you write a provider and wish to share it, please let me know and I will send a link your way.

Get the latest bits with the new provider model at CodePlex.

* $4.95/month BlogEngine.net Hosting – Click Here!

Comments (4) -

harsha
harsha
4/11/2007 3:43:00 PM #

Hey Mads,
How do I add the your calender control to the blog?

Mads Kristensen
Mads Kristensen
4/11/2007 3:50:50 PM #

I haven't uploaded it to CodePlex yet, but will later today. I want to test it on this blog before release. There will also be a admin page for managing categories - delete and rename.

Mads Kristensen
Mads Kristensen
4/11/2007 3:53:52 PM #

also, comments are now themeable as well. To pull it off, I had to put a <form runat="server"> on the site.master in each theme, so remember to update it.

Marwan
Marwan Tunisia
12/10/2008 5:38:34 PM #

I think, the MemebershipProvider and the RoleProvider should be also changed to the same data provider.

Comments are closed

About the author

Mads Kristensen

Mads Kristensen
Program Manager at the Microsoft Web Platform team and founder of BlogEngine.NET.

More...

Month List

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer’s view in any way.