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
  11:   
  12:          public static void RegisterRoutes()
  13:          {
  14:              RouteTable.Routes.Add(new Route("PageTypeUsage.aspx", new RouteHandler()));
  15:          }
  16:   
  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!

32 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. 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

    ReplyDelete
  3. 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



    ReplyDelete
  4. 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

    ReplyDelete
  5. 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

    ReplyDelete
  6. 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


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

    ReplyDelete
  8. This comment has been removed by the author.

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

    ReplyDelete
  10. 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

    ReplyDelete
  11. I feel really happy to have seen your web page and look forward to so many more entertaining times reading here. Thanks once more for all the details.
    he contents are masterpiece. you have done a fantastic activity on this subject!

    Data Science Training In Chennai

    Data Science Online Training In Chennai

    Data Science Training In Bangalore

    Data Science Training In Hyderabad

    Data Science Training In Coimbatore

    Data Science Training

    Data Science Online Training

    ReplyDelete
  12. seo tools buy is the only trusted website in india at the moment.

    ReplyDelete
  13. using scratch coding has becoming unpopular since Group Buy SEO Tools introduced in the market. its ease the developer works and save their times

    ReplyDelete
  14. Seo group buy tools is a term used for sharing SEO tools in groups if you can't afford them individually.


    Seogroupbuyguru.com offers a platform for a reasonable price to share these expensive tools.. Therefore, an original tool is shared between those who can't subscribe from official sellers.

    ReplyDelete
  15. We provide our clients with premium quality hearing aids that are available in a singapore.

    ReplyDelete
  16. StockTrim is inventory planning and demand forecasting software available as a subscription. It helps SME's gain optimised inventory levels and preserves up to 40% of their working capital.Stock Control

    ReplyDelete
  17. This is a real good and well written article about the best forex trading robot to trade the market with. In fact, I think that you should really take a look buy aged bulk gmail twitter instagram accounts pva youtube buy instagram accounts instagram pva accounts buy bulk instagram accounts pvaaccountss com at this, since I think it'll really help you out when it comes to trading. Thank you for writing this article, I am indeed looking forward to your articles as I've learned a lot from it. Indeed I hope you enjoyed this article and I hope you take what you have learned here and use it to make yourself successful in the forex trading market.Buy snapchat account

    ReplyDelete
  18. Are you one of the thousands of people who have seen advertisements on social accounts earning thousands of dollars per day? Or are you simply one of the many who have joined these programs in hopes of making some easy money on the internet? In either case, you should know that making a social media account and advertising to it can lead to your business making a social accounts profit. It's true that these types of marketing efforts cost nothing to join, but most business owners don't know how to effectively use them to their advantage. Here are some tips that will help you get the most out of your social media marketing efforts:Buy pinterest accounts

    ReplyDelete


  19. I was just examining through the web looking for certain information and ran over your blog.It shows how well you understand this subject. Bookmarked this page, will return for extra. data science course in vadodara

    ReplyDelete
  20. You are looking for the most reliable, cheap and reliable seo tools supplier in 2021. You can join the best group buy seo tools here

    ReplyDelete
  21. Extremely overall quite fascinating post. I was searching for this sort of data and delighted in perusing this one. Continue posting. A debt of gratitude is in order for sharing.360digitmg-data science data analytics course in surat

    ReplyDelete
  22. Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here. business analytics course in mysore

    ReplyDelete
  23. Jasper.ai Group Buy are a great way to get your website seen by a larger audience and drive more traffic and sales to your site. Simply sign up for a group buy and let us take care of the marketing and advertising for you. We will create a custom campaign that targets your target audience and drives traffic to your website.

    ReplyDelete
  24. A good blog always comes-up with new and exciting information and while reading I have feel that this blog is really have all those quality that qualify a blog to be a one
    business analytics course in hyderabad

    ReplyDelete
  25. If you are looking for the best way to take your company to the next level and increase your revenue, a Digi uprise Course might be the answer. The Internet as well as social networks make it possible for firms to reach a wider audience and generate revenue with little effort. But, the most important thing is to understand how to make use of these tools and techniques to your advantage. In the present, there is many top institutes that will help you master these skills.

    ReplyDelete
  26. The
    Best Dietitian and Nutritionist in Delhi - Diet Mantra by Monika
    by Monika is focused on providing expert nutritional advice to suit your body needs and empowering you in making lasting lifestyle changes. One of the biggest challenges one faces in today’s fast-paced life is how to actually keep up with the time crunch and how to actually follow a healthy lifestyle. Taking the right regimen for good wellbeing is significant and according to the various maladies and diseases, it is critical to have a solid eating routine with the goal that the immunity system could help to defend the infection and can help to improve your health. We offer online diet consultation so our customers get handily associated with us with no hustle. Monika Manchanda has been awarded as the best dietitian & nutritionist in Delhi.

    ReplyDelete
  27. Digital Marketing Course in Delhi is now an important method to market your business. It allows companies to interact with customers on multiple levels and make meaningful connections that create lasting relationships. The job of a digital marketing professional involves planning, creating, and implementing online marketing strategies. It can encompass web design and management of social media, the optimization of search engines and content creation.

    ReplyDelete