Compartilhar via


Another SSDS sample: BlogEngine.NET on SSDS

As a by-product of a project I'm working on, I've got a working version of BlogEngine.NET on SSDS. You can download the provider and other related components from LitwareHR's web site releases section here.

In the package you will find:

  1. The SSDS based BlogProvider
  2. An SSDS based Membership & Role Providers for the web site
  3. Unit tests for all (with about 93% coverage for the provider)
  4. A simple tool for pre-loading the SSDS container with information that BlogEngine need to start

The underlying data access is inspired on LitwareHR's, although I've heavily refactored it. The key ideas remain the same: there's a Repository<T> type, it uses SOAP to access SSDS, etc. but the code is simpler, responsibilities are better balanced and distributed, and I eliminated superfluous code here and there.

The new SSDS BlogProvider also uses patterns & practices Unity application block to wire up dependencies, so you write things like this:

 public override Post SelectPost(Guid id)<br>{    Post be_post;<br>    Entities.Post post;    using (IRepository<Entities.Post> r_post = RepositoryFactory.Build<Entities.Post>())<br>    {<br>       post = r_post.GetById(id); 


        if( post == null )          return null;<br>    }<br>    be_post = SSDSPostToBEPost(post);    return post; 




}

RepositoryFactory.Build<T>() will use Unity's Resolve() method to find the appropriate Repository implementation and all its dependencies configured. Build<T>() body looks approximately like this:

 c.RegisterType(typeof(ITenantManager), typeof(DefaultTenantManager));<br>c.RegisterType<SitkaProxyFactory, SitkaProxyFactory>();<br>c.RegisterType( typeof(EntityMapper<T>), typeof( GenericMapper<T> ) );<br>c.RegisterType( typeof(IRepository<T>), typeof( Repository<T> ) );<br>IRepository<T> r = c.Resolve<IRepository<T>>();<br>r.TenantId = Constants.BlogEngineContainer;<br>return r; 

I'm still learning about Unity so there might be better ways of implementing what I did, but it works.

 

Things I've liked about BlogEngine.NET:

  • The provider model. I think it was great design decision that allowed me to write this fairly quickly. I didn't want to look to much into other pieces of BlogEngine.NET, and this provided a clear separation. 
  • The code structure is quite neat. Navigating it was painless and I used the same structure implemented in the XmlBlogProvider.
  • It's a nice app with a lot of functionality and a fun project to work with!

Things that I missed or would have liked to be different:

  • The one thing I missed the most is pre-built unit tests for the provider. 
  • There are some assumptions on the engine and core components about where it runs (particularly ASP.NET) that introduced some issues.
  • I only changed 1 line of code (which was superfluous anyway), and that is this in the Category class in BlogEngine.Core:
 internal static string _Folder = System.Web.HttpContext.Current.Server.MapPath(BlogSettings.Instance.StorageLocation); 

This prevented me from unit testing my provider in complete isolation. It turns out that the variable wasn't needed anyway, so I commented it out.

  • There are other features in the app that are not abstracted in the provider (or in another replaceable component). For example, file attachments are handled in the Add_Entry.aspx web page. I didn't want to use the file system at all, but I also didn't want to change the code, so I left it as is. There are other parts of the app that have direct dependencies like this.
  • I wasn't sure about the app exception handling architecture, so I opted to do what the other providers seem to be doing: just throw and hope the upper layers handle it :-).

 

BlogEngine.NET expects some initial data: a user, an admin role and some initial settings. The unit tests will make sure these exist prior to running, and I also created a "Provisioning" console application that populates the container with the needed information. You need to configure all appropriate configuration files with your SSDS credentials.

Finally, because I'm using LitwareHR's data access, you can use the offline proxy to test the system independently from SSDS. So, until you get the SSDS beta account, you can start playing with it.

Feedback is welcome, as usual.

Comments

  • Anonymous
    June 11, 2008
    This is great... it will save some time to. Yesterday got my beta account for SSDS and the first thing I started with, is porting my blog based on blogengine.net to use SSDS… thanks. For sure feedback will follow ;-)

  • Anonymous
    June 11, 2008
    i think that the blogengineis finding its position on the blog engines and the good thing is that it is using new technologies and i think that with fans it will be developed rapidly.

  • Anonymous
    June 16, 2008
    Allez, avouez, vous n'avez rien pig&#233; au titre de ce billet, si ? Alors je vous le refais en clair

  • Anonymous
    June 17, 2008
    The comment has been removed

  • Anonymous
    August 13, 2008
    I have been learning SSDS and trying to use your code blogengine ssds source code to build my application. I spent last 2 days.. couldn't find a reason... I am running into a problem, when i compile and run the application, the code fails here: ISitkaSoapService proxy = factory.Build("SitkaProxy"); --> calls the function: public TTypeToBuild Build(string settingsKey)        {            string typeName = System.Configuration.ConfigurationSettings.AppSettings[settingsKey];            TTypeToBuild typeToBuild;            if (string.IsNullOrEmpty(typeName))            {                return new TDefaultType();            }            else            {                typeToBuild = Activator.CreateInstance(Type.GetType(typeName)) as TTypeToBuild;            }            return typeToBuild;        } And I get TargetInvocationException at : typeToBuild = Activator.CreateInstance(Type.GetType(typeName)) as TTypeToBuild; the innerexception shows: {"Could not find default endpoint element that references contract 'SitkaClient.ISitkaSoapService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element."} i checked all the code/files.. am not sure what i am missing.. any help.. appreciate it..

  • Anonymous
    August 24, 2008
    This looks like a misconfiguration. Check web.config.

  • Anonymous
    October 05, 2008
    I have been reading about cloud computing quite a bit.&#160; I found that Microsoft is doing something

  • Anonymous
    March 07, 2009
    I am very much interested on BlogEngine.NET using SSDS.  I've downloaded your code but I can't see source in handling NewMediaObject.  Where to save blob...on SSDS or Windows Azure blobs?  Thanks!

  • Anonymous
    March 08, 2009
    The comment has been removed

  • Anonymous
    September 14, 2009
    I think you have some code that need to replace to avoid mis configuration. Oes Tsetnoc

  • Anonymous
    September 17, 2009
    yes..i think their is some  misconfig in your code and you should better fixed it..you can ask this forum to ask for some codes..they are expert.. ( http://www.daniweb.com )..for sure they can help you..

  • Anonymous
    September 17, 2009
    This version of SDS is not longer available. So this sample is not applicable any more. SDS is now SQL Azure which is compatible with SQL Server. Most probably BlogEngine default provider would "just work".

  • Anonymous
    September 23, 2009
    the code is perfect and i think it is effective

  • Anonymous
    September 25, 2009
    Thank you very much for the nice information. It is very useful. Ed Hardy

  • Anonymous
    September 27, 2009
    great i use this code and i think it is perfect.

  • Anonymous
    October 06, 2009
    wow..great..this is very useful for some beginners like me.

  • Anonymous
    October 08, 2009
    I am still trying to figure out this code and about to study this. I still need time to see the real purpose of this code, maybe because its quite new to me.

  • Anonymous
    October 23, 2009
    Thanks for sharing this information. . Noah Group

  • Anonymous
    November 09, 2009
    Actually your blog looks good...but you must set up it SQL Server DBA.

  • Anonymous
    July 25, 2010
    Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me.

  • Anonymous
    September 23, 2010
    I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.

  • Anonymous
    March 13, 2011
    I admire your article.It contains valuable information.Thanks for Sharing.