<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title type="text">Blog posts by Jesus Escandon</title><link href="http://world.optimizely.com" /><updated>2017-12-08T04:18:54.0000000Z</updated><id>https://world.optimizely.com/blogs/jesus-escandon/</id> <generator uri="http://world.optimizely.com" version="2.0">Optimizely World</generator> <entry><title>Custom Initialization for your created Plugins/Modules - EPiServer CMS | create Plug-ins using MVC</title><link href="https://world.optimizely.com/blogs/jesus-escandon/dates/2017/12/custom-initialization-for-custom-plugins---episerver-cms/" /><id>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;p&gt;I&#39;m by no means an expert and because of this I&#39;m trying to share the new things I have learn using EpIServer, reason why I try to be as explicit as I can for all the new deveopers like me, good luck. &lt;strong&gt;#sharingiscaring&lt;/strong&gt; :)&amp;nbsp;&lt;/p&gt;
&lt;p&gt;By the way this example is thanks to my Episerver Guru, that her name I will not share but if at any point in time she read this post, thanks you Rock!!!&lt;/p&gt;
&lt;p&gt;In EPiServer [7.5 +] it&#39;s need it to register the route of your custom plugin/module, here you can find a CustomInitialization code that will initialize all your custom plugins (works for just one or many), in my proyect I place this class in the modules folder located in my project root directory.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/link/e51693e3f37049219fbaa9bd5788b3f1.aspx&quot; alt=&quot;Image Custom INitialization.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;In this project I have a custom plugin in the folder ImportProduct, is important that your plugin class controller is properly decorated using the [GuiPlugIn()], and with this class you will register any custom plugin/module you have created in EPiServer.&lt;/p&gt;
&lt;p&gt;I create this class like this: Right click on folder modules -&amp;gt;&amp;nbsp; Add new Item -&amp;gt; select create a new Initialization Module with HTTP events from Episerver.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/link/f26d6d55758f4b6ebcecf5ebff28526d.aspx&quot; alt=&quot;Image Custom INitialization.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;And name it: CustomInitialization.cs&lt;/p&gt;
&lt;p&gt;Now we have a class teamplate to work with, the fist thing to do is remove the class decoration or you can comment this using the // at the begining of each line:&lt;/p&gt;
&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt; [InitializableModule]
    [ModuleDependency(typeof(EPiServer.Web.InitializationModule))]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As what we want to do is not to create an Initializable module, we want to create our custom Map Route for any of our Plugins/modules.&lt;/p&gt;
&lt;p&gt;Then this is the inside logic:&lt;/p&gt;
&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;using System.Web.Mvc;
using System.Web.Routing;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;

namespace YourProjectName.Site.modules
{
public class CustomInitialization : IInitializableModule
    {
        private string _pluginName { get; set; }

        public CustomInitialization(string pluginname)
        {
            _pluginName = pluginname;
        }

        public void Initialize(InitializationEngine context)
        {
            RouteTable.Routes.MapRoute(
                null,
                &quot;modules/&quot; + _pluginName,
                new { controller = _pluginName, action = &quot;Index&quot; });
        }

        public void Uninitialize(InitializationEngine context)
        {
            //Add uninitialization logic
        }
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now in you pluing/module folder create a Initialization folder and add a new class using the Initialization Module Type and&amp;nbsp; name it CustomRouteInitialization.cs&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/link/f26d6d55758f4b6ebcecf5ebff28526d.aspx&quot; alt=&quot;Image Custom INitialization.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/link/4e5fa2d6316846d493133f26c4358ef0.aspx&quot; alt=&quot;Image Custom INitialization3.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This is the logic inside this class, in this case we want to have the [InitializableModule] decoration as this is what tell EPiServer that this is a initializable module.&lt;/p&gt;
&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;using EPiServer.Framework;

namespace YourProjectName.Site.modules.ImportProduct.Initialization
{
    [InitializableModule]    
    public class CustomRouteInitialization : CustomInitialization
    {
        public CustomRouteInitialization() : base(&quot;importproduct&quot;)
        {

        }
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Thats all you need.&lt;/p&gt;
&lt;p&gt;So this logic will create the MapRoute of any pluing/module that is decorated with the [InitializableModule], IMPORTANT!!! notice in our CustomRouteInitialization is where we use our CustomInitialization class and pass it our plugin name: &quot;importproduct&quot; so the route can be register, this step you will need to do it inside any plugin/module you create.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;As I want to avoid any missing parts, inside the folder ImportProduct is my custom module, I have a class of type controller named: ImportProductController.cs and it is decorated with the [GuiPlugIn()] and looks like this:&lt;/span&gt;&lt;/p&gt;
&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;using System.Web.Mvc;
using EPiServer.PlugIn;

namespace YourProjectName.Site.modules.ImportProduct
{
    [GuiPlugIn(
        Area = PlugInArea.AdminMenu,
        Url= &quot;/modules/importproduct&quot;,
        LanguagePath= &quot;/Plugin/ImportProduct&quot;)]
    public class ImportProductController : Controller
    {
        public string Index()
        {
            /* Implementation of action. You can create your own view model class that you pass to the view or
             * you can pass the page type for simpler templates */

            return &quot;Hello World! one step closer :)&quot;;
        }
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span&gt;This &quot;Plug-in&quot; will be display in the admin section of EPiServer (was the resquest) so if you follow this post you should be able to see your &quot;super cool plug-in&quot; like this (and sorry for my poor paint skills):&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img src=&quot;/link/e1547e5248a34f47afbd5e68a4b74d0f.aspx&quot; alt=&quot;Image Custom INitialization4.png&quot; /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Hope you will find this usefull and that I use the right terminology, good luck!!!&lt;/span&gt;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</id><updated>2017-12-08T04:18:54.0000000Z</updated><summary type="html">Blog post</summary></entry></feed>