<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nishant Chaudhary on Medium]]></title>
        <description><![CDATA[Stories by Nishant Chaudhary on Medium]]></description>
        <link>https://medium.com/@info_nishant?source=rss-145180fbd75c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*M2BHKv0ySqLwQbQRn932rg.jpeg</url>
            <title>Stories by Nishant Chaudhary on Medium</title>
            <link>https://medium.com/@info_nishant?source=rss-145180fbd75c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 13:58:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@info_nishant/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to create a modular web application in C# MVC]]></title>
            <link>https://medium.com/@info_nishant/how-to-create-a-modular-web-application-in-c-mvc-85d8074a26bc?source=rss-145180fbd75c------2</link>
            <guid isPermaLink="false">https://medium.com/p/85d8074a26bc</guid>
            <category><![CDATA[aspnet-mvc]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[mvc]]></category>
            <category><![CDATA[web-applications]]></category>
            <category><![CDATA[modular]]></category>
            <dc:creator><![CDATA[Nishant Chaudhary]]></dc:creator>
            <pubDate>Fri, 12 Aug 2016 04:31:01 GMT</pubDate>
            <atom:updated>2016-08-16T07:17:55.257Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Scenario</strong></p><p>When a web application has multiple modules (or sub-applications/ features) it tends to get larger. So, the more modules you plug in your application, the more complex it becomes to partition and maintain the code.</p><p><strong>What is the trick to solving this?</strong></p><p>A solution for the above problem is to develop application modules independently, without any direct dependencies among them and also on the main application code. Developers should always opt for a modular solution, in which larger modules are easily maintained over time, separately. Once each module is ready for integration, they could be then plugged into the main application with little to no adjustment of the same.</p><p>So in short, the structure of a complex asp.net MVC application can be very easily maintained using <strong><em>areas</em></strong>. The concept of this is to allow us to breakdown a large complex application into a several small sections called areas.</p><p>These areas can have their own set of: <br> 1. Models<br> 2. Views<br> 3. Controllers<br> 4. Routes</p><p>In this article we are going to develop an ASP.NET MVC application that contains loosely coupled modules (independent to main application), which we will further plug in the main application.</p><p><strong>Benefits of this approach</strong></p><p>This approach is extremely useful for product development. Utilizing this approach, each module may be developed and deployed for the product separately. This helps in building different versions of the product, like basic, professional, premium, and enterprise versions. It also enables product developers to create the isolation required to</p><p>ü Build separate installers with the required features for each different version</p><p>ü A master setup which can only install defined features as per license key used during installation, or</p><p>ü Some other configuration that requires the modular separation technique.</p><p><strong>Demo for a Modular App</strong></p><p>Here we will create a web application that contains the following modules:</p><p>· Sale</p><p>· Purchase</p><p>· Maintenance</p><p>· Marketing</p><p>· Stock</p><p>· Import</p><p>· Export</p><p><strong>Step 1:</strong></p><p>Open Visual Studio 2015 and create an ASP.NET MVC project as follows. Give it a meaningful name (in my case I have used <em>MVCPluggableDemo</em>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*WvnSJiAJmnaof__-KswOEA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*Kgv8ed2uSIr0XqqiWaAWug.png" /></figure><p>Once it is created, your solution should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*-6zIhbRWLgDZNyl962re2A.png" /></figure><p><strong>Step 2:</strong></p><p>Right-click on the ‘Controllers’ folder and select “Add -&gt; Controller”. Name it <em>HomeController</em>, and select “Empty MVC Controller” for the template:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*jXokHQJpX7rXmZ0Ar9WNkA.png" /></figure><p>Right-click on the Index method of the controller and select “Add View”. Using defaults, create the Index view for HomeController to form the landing page for the application:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*mfXJiE5H6b2G_aHwv0JP9Q.png" /></figure><p><strong>Step 3:</strong></p><p>Now edit the highlighted section in <strong>_Layout.cshtml</strong> (under the Views\Shared folder) in order to create menu items pointing to the desired modules:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LDv7AMuMU2QKOpbgJFWi_w.png" /></figure><p><strong>Step 4:</strong></p><p>Run the application and you will get the output as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FoO_qVxRsuExUKRbSYCjHQ.png" /></figure><p><strong>Now we will focus on creating separate modules for our application and then plug them into the main one.</strong></p><p><strong>Step 5:</strong></p><p>Right-click on the main application project title (as in our case <strong>MVCPluggableDemo</strong>) in the Solution Explorer and select “Add-&gt;Area” from the context menu. This will create a basic folder structure for the Area framework. Specify “Sale” as Area name and click “Add”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*BhNA3YI21p2AkK69tX5S-Q.png" /></figure><p>Then we have a folder solution structure that looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/313/1*vFDYKeKLtxBZcRW9Mmwhxg.png" /></figure><p><strong>Step 6:</strong></p><p>Take a backup of the <strong>SaleAreaRegistration.cs</strong> file. This file will be needed later on when we add the Sale module to the solution as a separate project.</p><p>Now remove the Sale subfolder from the Areas folder, keeping the Areas folder in place.</p><p>Next add the new pluggable module for “Sale”, right-click on the solution and choose “Add-&gt; New Project”.</p><p>· Select Empty ASP.NET MVC Application</p><p>· Name to project ‘Sale’</p><p>· Set Location as “<strong>…\MVCPluggableDemo\MVCPluggableDemo\Areas\</strong>”</p><p>· A new project should be created in the Areas folder (previously created).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*3tXe9pyJ0r18E1QubBa9Rg.png" /></figure><p>After this step, your solution should look like the one below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/317/1*lQKCqDRgKX6mEEXTuQeIWQ.png" /></figure><p>As we saved new project Sale under the Areas folder, it appears as hidden folder under the MVCPluggableDemo/Areas folder in the Solution Explorer:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*sC_13uoyQF275H7qCM4Xng.png" /></figure><p><strong>Step 7:</strong></p><p>Adjust the MVCPluggableDemo’s <strong>RouteConfig.cs</strong> file to properly add the correct namespace overload to the routes.MapRoute() method:</p><p>We will also use the other overloaded version of routes.MapRoute() method which takes the namespace of the Controller.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SJmiCllvrru6dxkfn4mZlg.png" /></figure><p><strong>Step 8:</strong></p><p>Set the output directory of <em>Sale</em> project to ..\..\bin\ so that it’s compiled DLLs are placed in the bin directory of the MVCPluggableDemo application:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wFoqeRzFzatIRY7WW9kL2g.png" /></figure><p>Setting related to connection strings, authentication, membership, role manager, profile, and session state are going to be placed in the web.config of your root directory. So remove all these section from the sale’s web.config.</p><p><strong>Step 9:</strong></p><p>· Create the Sale controller in the Sale project.</p><p>· Create an Index view and place the content “Welcome to Sales Module” in its header.</p><p><strong>Step 10:</strong></p><p>Now add SaleAreaRegistration.cs file (Backup file from step 6) to the root directory of the Sale project and change its namespace to <em>MVCPluggableDemo</em>; use the overloaded version of <em>context.MapRoute()</em> method which accepts the namespace of the controller to use as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SwGxXyZn5mDn5flyFmFmOA.png" /></figure><p><strong>Step 11:</strong></p><p>Now build the solution and check the <em>MVCPluggableDemo\bin</em> folder and you will have the compiled DLLs for the Sale module there:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*9x6B-QfheF942rKCfyJBaQ.png" /></figure><p><strong>Step 12:</strong></p><p>Now run the application! If you have followed all the steps correctly, it will be working as expected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nFtA71r_x8EXR45XW2IShw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lyHBAhSyz2que_omLd1wpg.png" /></figure><p>You can follow the same steps and create other larger modules separately and plug them in to your application. Isn’t it simple yet such a powerful feature when it comes to product development?</p><p>Post your comments, doubts and queries below. The demo application is also available for download <a href="https://www.dropbox.com/s/zfmn3p9bebc4dxv/MVCPluggableDemo.zip?dl=0"><strong>here</strong></a>. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85d8074a26bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>