Tuesday, November 5, 2013

EPiServer 6: Sharing plugins between applications

In this example I will demonstrate the possibility to share EPiServer plugins between applications. The idea is to make this as seamless as possible without configuration or having to add front-end files into every project.

What we will do is to create a class library project, build a release DLL and put this DLL into the bin folder of another project. And all of this will produce a new admin tool as depicted below.

Create the plugin

We create the plugin and what is worth noting here is the Url on line 4 (this is used with the route helper, see below) and the inheritance of the IPageTypeUsage interface on line 5.

   1:  [GuiPlugIn(DisplayName = "Page Type Usage",
   2:              Description = "See the usage of a selected page type.",
   3:              Area = PlugInArea.AdminMenu,
   4:              Url = "/PageTypeUsage.aspx")]
   5:  public class PageTypeUsage : Page, IPageTypeUsage

We will not use an ASPX file at all but instead add all the controls needed to the ControlCollection of the plugin page. And this must be added in the OnInit method in order to be able to use them properly.

   1:  protected override void OnInit(EventArgs e)
   2:  {
   3:      AddControls();
   4:      InitPageTypesDropDown();
   5:      base.OnInit(e);
   6:  }

A little example of the AddControls method. Once added they will render properly without us having to doing anything in particular.

   1:  private void AddControls()
   2:  {
   3:      HtmlGenericControl html = new HtmlGenericControl("html");
   4:      HtmlHead head = new HtmlHead();
   5:      HtmlTitle title = new HtmlTitle { Text = "Page Type Usage" };
   6:      HtmlGenericControl javascript = ControlHelper.GetJavaScriptLinkControl("/util/javascript/system.js");
   7:      HtmlGenericControl css1 = ControlHelper.GetCssLinkControl("/epi/Shell/ClientResources/ShellCore.css");
   8:      Controls.Add(html);
   9:      html.Controls.Add(head);
  10:      head.Controls.Add(title);
  11:      head.Controls.Add(javascript);
  12:      head.Controls.Add(css1);

Route handler

In order for this to work without using an ASPX file and having a virtual path we will use the power of Routes.

   1:      public class RouteHandler : PlugInAttribute, IRouteHandler
   2:      {
   3:          #region IRouteHandler Members
   4:          public IHttpHandler GetHttpHandler(RequestContext requestContext)
   5:          {
   6:              var interfaceType = typeof(IPageTypeUsage);
   7:              var classType = AppDomain.CurrentDomain.GetAssemblies().SelectMany(s => s.GetTypes()).First(p => interfaceType.IsAssignableFrom(p) && p.IsClass);
   8:              return Activator.CreateInstance(classType) as IHttpHandler;
   9:          }
  10:          #endregion
  12:          public static void RegisterRoutes()
  13:          {
  14:              RouteTable.Routes.Add(new Route("PageTypeUsage.aspx", new RouteHandler()));
  15:          }
  17:          public static void Start()
  18:          {
  19:              RegisterRoutes();
  20:          }
  21:      }

By inheriting PlugInAttribute on line 1 we can access the Start method (on line 17) and register the routes. And we register the route "PageTypeUsage.aspx" - which is the same as we specified on the plugin. Once this route is hit or accessed the GetHttpHandler method on line 4 is used. Basically this utilize a reflection search of the interface IPageTypeUsage and instantiates a PageTypeUsage object (on line 8).

And voila! We have a plugin that we can share between different projects!


  1. When I initially commented, I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get several emails with the same comment. Is there any way you can remove people from that service? Thanks.

    AWS Training in Bangalore | Amazon Web Services Training in Bangalore

    Amazon Web Services Training in Pune | Best AWS Training in Pune

    AWS Online Training | Online AWS Certification Course - Gangboard

  2. This comment has been removed by the author.

  3. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.

    angularjs Training in chennai
    angularjs Training in chennai

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

  4. After seeing your article I want to say that the presentation is very good and also a well-written article with some very good information which is very useful for the readers....thanks for sharing it and do share more posts like this.
    python training in velachery | python training institute in chennai

  5. The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.
    advanced excel training in bangalore

  6. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    blueprism training in chennai | blueprism training in bangalore | blueprism training in pune | blueprism online training

  7. You blog post is just completely quality and informative. Many new facts and information which I have not heard about before. Keep sharing more blog posts.
    Java training in Jaya nagar | Java training in Electronic city

    Java training in Chennai | Java training in USA | Java training in Kalyan nagar

  8. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.

    Data Science training in Chennai | Data science training in bangalore

    Data science training in pune | Data science online training

    Data Science Interview questions and answers

  9. 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.

    devops online training

    aws online training

    data science with python online training

    data science online training

    rpa online training

  10. This comment has been removed by the author.

  11. Nice blog,I understood the topic very clearly,And want to study more like this.
    Data Scientist Course

  12. I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.

    digital marketing course

  13. if you want to learn digital marketing in mumbai. excelr solutions providing best AI course in mumbai.for more details click here

    digital marketing courses in mumbai

  14. Attend The Data Analytics Courses From ExcelR. Practical Data Analytics Courses Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Data Analytics Courses.
    Data Analytics Courses
    Data Science Interview Questions

  15. Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!
    ExcelR digital marketing courses in mumbai

  16. wonderful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article resolved my all queries.
    Data Science Course

  17. After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article.

    data science course

  18. It's a wonderful post and very helpful, thanks for all this information about Java. You are including better information regarding this topic in an effective way.Thank you so much.
    Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery

  19. I am looking for and I love to post a comment that "The content of your post is awesome" Great work!

    Correlation vs Covariance

  20. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Correlation vs Covariance
    Simple linear regression

  21. I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got here. Big thumbs up for making such wonderful blog page!
    AWS training in chennai | AWS training in annanagar | AWS training in omr | AWS training in porur | AWS training in tambaram | AWS training in velachery

  22. I am looking for and I love to post a comment that "The content of your post is awesome" Great work!

    Simple Linear Regression

    Correlation vs Covariance