<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>areas on Marcin Zabłocki blog</title>
    <link>https://zablo.net/tags/areas/</link>
    <description>Recent content in areas on Marcin Zabłocki blog</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <managingEditor>Marcin Zabłocki</managingEditor>
    <webMaster>Marcin Zabłocki</webMaster>
    <copyright>2026 Marcin Zabłocki</copyright>
    <lastBuildDate>Mon, 21 Mar 2016 23:00:00 +0000</lastBuildDate>
    <atom:link href="https://zablo.net/tags/areas/index.xml" rel="self" type="application/rss+xml"/>
    <item>
      <title>Modular ASP.NET Core 1.0 project structure</title>
      <link>https://zablo.net/blog/post/modular-asp-net-core-project-structure/</link>
      <pubDate>Mon, 21 Mar 2016 23:00:00 +0000</pubDate>
      <author>Marcin Zabłocki</author>
      <guid>https://zablo.net/blog/post/modular-asp-net-core-project-structure/</guid>
      <category>asp.net-core</category>
      <category>asp.net-5</category>
      <category>components</category>
      <category>project</category>
      <category>areas</category>
      <description>&lt;p&gt;ASP.NET Core 1.0 (formely ASP.NET 5) introduced some new framework concepts as well as cut loose the project structure, giving the developers ability to fully customize it. In example, we are no more bound to the Areas folder structure, which in my opinion unnecessarily duplicated Controllers/Models/Views folder structure in each of them.&lt;/p&gt;&#xA;&lt;p&gt;Moreover, new version of the framework added a feature called View Components, which finally resolved issue of having additional controllers returning only partial views. From now on, we can make true components in ASP.NET without any workarounds.&lt;/p&gt;&#xA;&lt;p&gt;I&amp;rsquo;ve already written a few projects in ASP.NET Core 1.0 and here is how I worked my way into creating elastic project structure.&lt;/p&gt;&#xA;&lt;h2 id=&#34;well-structured-areas&#34;&gt;Well structured areas&lt;/h2&gt;&#xA;&lt;p&gt;First of all - the areas. They are in ASP.NET MVC for quite a while and they are really useful. Personally, I&amp;rsquo;ve used them every time when I had to write application with both &lt;strong&gt;admin panel&lt;/strong&gt; and &lt;strong&gt;client facing pages&lt;/strong&gt;. The bigger part usually landed inside main project structure and the smaller one inside the &lt;em&gt;Areas folder&lt;/em&gt;. And&amp;hellip; I hated that. I wanted &lt;strong&gt;Controllers inside the &lt;em&gt;Controllers folder&lt;/em&gt;&lt;/strong&gt;, Views inside Views folder and Models inside Models folder. Finally - I can do that really easily.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s say we have three areas: Main (client facing), Administrator and Content Authors. The output of the following configuration will look like this.&lt;/p&gt;&#xA;&lt;figure class=&#34;codeblock on-ink&#34;&gt;&#xA;  &lt;figcaption class=&#34;codeblock__caption&#34;&gt;&#xA;    &lt;span class=&#34;codeblock__lang&#34;&gt;html&lt;/span&gt;&#xA;    &lt;span class=&#34;codeblock__caption-right&#34;&gt;&#xA;      &lt;button type=&#34;button&#34; class=&#34;codeblock__copy&#34; aria-label=&#34;Copy code to clipboard&#34;&gt;Copy&lt;/button&gt;&#xA;    &lt;/span&gt;&#xA;  &lt;/figcaption&gt;&#xA;  &lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-html&#34; data-lang=&#34;html&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;projectroot&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;└───Controllers&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    └───Admin&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    └───Authors&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    └───HomeController.cs&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    └───(...) other client controllers&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;└───Views&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    └───Admin&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    └───Authors&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    └───Shared&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    └───Home&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        └───Index.cshtml&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        └───(...) other client views&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;└───Models&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    └───Admin&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    └───Authors&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    └───(...)HomePageViewModel.cs&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;As you can see, Admin and Author controllers are placed inside Controllers folder - it is where you would start looking for any controller in somebody else&amp;rsquo;s project, don&amp;rsquo;t you?&#xA;The same rule applies for the Views and Models (actually - View Models) folders.&lt;/p&gt;&#xA;&lt;p&gt;To make this structure work, the only thing we need to do is to &lt;strong&gt;extend Razor View Engine&lt;/strong&gt;, so it will know &lt;strong&gt;how to find Views for particular Area&lt;/strong&gt;. This can be done by implementing &lt;em&gt;IViewLocationExpander&lt;/em&gt; interface:&lt;/p&gt;&#xA;&lt;figure class=&#34;codeblock on-ink&#34;&gt;&#xA;  &lt;figcaption class=&#34;codeblock__caption&#34;&gt;&#xA;    &lt;span class=&#34;codeblock__lang&#34;&gt;csharp&lt;/span&gt;&#xA;    &lt;span class=&#34;codeblock__caption-right&#34;&gt;&#xA;      &lt;button type=&#34;button&#34; class=&#34;codeblock__copy&#34; aria-label=&#34;Copy code to clipboard&#34;&gt;Copy&lt;/button&gt;&#xA;    &lt;/span&gt;&#xA;  &lt;/figcaption&gt;&#xA;  &lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kd&#34;&gt;public&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;ViewLocationExpander&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;IViewLocationExpander&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;kd&#34;&gt;public&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;void&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;PopulateValues&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ViewLocationExpanderContext&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;context&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;c1&#34;&gt;// nothing here&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;kd&#34;&gt;public&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;IEnumerable&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;string&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;ExpandViewLocations&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ViewLocationExpanderContext&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;context&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;IEnumerable&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;string&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;viewLocations&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;kt&#34;&gt;var&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;area&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;            &lt;span class=&#34;n&#34;&gt;context&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ActionContext&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ActionDescriptor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;RouteConstraints&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;FirstOrDefault&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;rc&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;rc&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;RouteKey&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;area&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;kt&#34;&gt;var&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;additionalLocations&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;new&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;LinkedList&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;string&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;();&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;area&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;!=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;null&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;            &lt;span class=&#34;n&#34;&gt;additionalLocations&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;AddLast&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;$&amp;#34;/Views/{area.RouteValue}&amp;#34;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;{1}/{0}.cshtml&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;viewLocations&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Concat&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;additionalLocations&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;Now we need to attach this class to Razor engine. Head to &lt;em&gt;Startup.cs&lt;/em&gt; and find the line in which you add MVC to application services:&lt;/p&gt;&#xA;&lt;figure class=&#34;codeblock on-ink&#34;&gt;&#xA;  &lt;figcaption class=&#34;codeblock__caption&#34;&gt;&#xA;    &lt;span class=&#34;codeblock__lang&#34;&gt;csharp&lt;/span&gt;&#xA;    &lt;span class=&#34;codeblock__caption-right&#34;&gt;&#xA;      &lt;button type=&#34;button&#34; class=&#34;codeblock__copy&#34; aria-label=&#34;Copy code to clipboard&#34;&gt;Copy&lt;/button&gt;&#xA;    &lt;/span&gt;&#xA;  &lt;/figcaption&gt;&#xA;  &lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;services&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;AddMvc&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;and extend this line in order to add &lt;strong&gt;Razor View Engine Options&lt;/strong&gt;:&lt;/p&gt;&#xA;&lt;figure class=&#34;codeblock on-ink&#34;&gt;&#xA;  &lt;figcaption class=&#34;codeblock__caption&#34;&gt;&#xA;    &lt;span class=&#34;codeblock__lang&#34;&gt;csharp&lt;/span&gt;&#xA;    &lt;span class=&#34;codeblock__caption-right&#34;&gt;&#xA;      &lt;button type=&#34;button&#34; class=&#34;codeblock__copy&#34; aria-label=&#34;Copy code to clipboard&#34;&gt;Copy&lt;/button&gt;&#xA;    &lt;/span&gt;&#xA;  &lt;/figcaption&gt;&#xA;  &lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;services&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;AddMvc&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;().&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;AddRazorOptions&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;razorOptions&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&amp;gt;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;razorOptions&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ViewLocationExpanders&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Add&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;new&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;ViewLocationExpander&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;());&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;});&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;From now on, for every controller marked with  &lt;strong&gt;&lt;em&gt;[Area]&lt;/em&gt;&lt;/strong&gt; atrribute, the framework will search for it&amp;rsquo;s views inside proper folder located under projects Views folder. Of course, this solution requires to have &lt;strong&gt;exactly the same name in the folder structure as in the attribute parameter&lt;/strong&gt;. If you want to have different area name and different folder names, just add some &lt;em&gt;if/switch&lt;/em&gt; inside of the &lt;em&gt;ExpandViewLocations&lt;/em&gt; method and you will be good to go.&lt;/p&gt;&#xA;&lt;h2 id=&#34;reusable--isolated-components&#34;&gt;Reusable &amp;amp; isolated components&lt;/h2&gt;&#xA;&lt;p&gt;Some time ago, somebody asked on Stackoverflow, where the JavaScript files for the View Components should be placed in ASP.NET Core 1.0 projects. I&amp;rsquo;ve responed for that question, and here is my point of view (link to the answer bellow the post).&lt;/p&gt;&#xA;&lt;p&gt;Isolation of components should not only consider JavaScript files, but also backing code (&lt;em&gt;ViewComponent class&lt;/em&gt;) and the component&amp;rsquo;s view razor file. In my projects, I tend to make this kind of structure for View Components:&lt;/p&gt;&#xA;&lt;figure class=&#34;codeblock on-ink&#34;&gt;&#xA;  &lt;figcaption class=&#34;codeblock__caption&#34;&gt;&#xA;    &lt;span class=&#34;codeblock__lang&#34;&gt;markdown&lt;/span&gt;&#xA;    &lt;span class=&#34;codeblock__caption-right&#34;&gt;&#xA;      &lt;button type=&#34;button&#34; class=&#34;codeblock__copy&#34; aria-label=&#34;Copy code to clipboard&#34;&gt;Copy&lt;/button&gt;&#xA;    &lt;/span&gt;&#xA;  &lt;/figcaption&gt;&#xA;  &lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-markdown&#34; data-lang=&#34;markdown&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&amp;lt;projectroot&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;└───Components&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    └───AwesomeComponent&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        └───Awesome.cshtml&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        └───AwesomeComponent.cs&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        └───AwesomeComponentModel.cs&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    └───CommentsComponent&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        └───Comments.cshtml&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        └───CommentsComponent.cs&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        └───CommentsComponentModel.cs&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;I treat every component as totally isolated entity. It is concise and it only contains necessary files. I can easily cut the component from my project and put it into another. For example, the Comments Component (actually used on this blog to show Discuss) just renders the required HTML with some dynamically rendered parameters passed to it&amp;rsquo;s view via CommentsComponentModel (which is the View Model).&lt;/p&gt;&#xA;&lt;p&gt;View, Backend code and Model are all in one place, so when you move around the component&amp;rsquo;s folder, you are sure that you move whole component. Moreover, when you are modyfying them, you have quick access to all of their parts.&lt;/p&gt;&#xA;&lt;p&gt;It will be convinient to put JavaScript and/or CSS files which are highly coupled with a component also in such structure. You can do this by simply creating the file under the component&amp;rsquo;s folder, and then writing a &lt;strong&gt;GULP TASK&lt;/strong&gt; that will copy JS/CSS files to &lt;strong&gt;wwwroot&lt;/strong&gt;. From that point, you will be able to link that JavaScript code on component&amp;rsquo;s .cshtml using standard syntax:&lt;/p&gt;&#xA;&lt;figure class=&#34;codeblock on-ink&#34;&gt;&#xA;  &lt;figcaption class=&#34;codeblock__caption&#34;&gt;&#xA;    &lt;span class=&#34;codeblock__lang&#34;&gt;html&lt;/span&gt;&#xA;    &lt;span class=&#34;codeblock__caption-right&#34;&gt;&#xA;      &lt;button type=&#34;button&#34; class=&#34;codeblock__copy&#34; aria-label=&#34;Copy code to clipboard&#34;&gt;Copy&lt;/button&gt;&#xA;    &lt;/span&gt;&#xA;  &lt;/figcaption&gt;&#xA;  &lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-html&#34; data-lang=&#34;html&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;script&lt;/span&gt; &lt;span class=&#34;na&#34;&gt;src&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;~/Components/awesomecomponent.js&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;script&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;After such setup, in order to render View Component with it&amp;rsquo;s parameters, use the following syntax:&lt;/p&gt;&#xA;&lt;figure class=&#34;codeblock on-ink&#34;&gt;&#xA;  &lt;figcaption class=&#34;codeblock__caption&#34;&gt;&#xA;    &lt;span class=&#34;codeblock__lang&#34;&gt;csharp&lt;/span&gt;&#xA;    &lt;span class=&#34;codeblock__caption-right&#34;&gt;&#xA;      &lt;button type=&#34;button&#34; class=&#34;codeblock__copy&#34; aria-label=&#34;Copy code to clipboard&#34;&gt;Copy&lt;/button&gt;&#xA;    &lt;/span&gt;&#xA;  &lt;/figcaption&gt;&#xA;  &lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;@await&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Component&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;InvokeAsync&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;AwesomeComponent&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;new&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;AwesomeComponentModel&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;And remember to put &lt;strong&gt;&lt;em&gt;[ViewComponent(Name = &amp;ldquo;Awesome&amp;rdquo;)]&lt;/em&gt;&lt;/strong&gt; annotation on the top of component&amp;rsquo;s backing class if you want to avoid adding full &lt;em&gt;(Name)ViewComponent&lt;/em&gt; convention and just have &lt;em&gt;(Name)Component&lt;/em&gt; classes.&lt;/p&gt;&#xA;&lt;h3 id=&#34;additional-links&#34;&gt;Additional links&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;My Stackoverflow anwser for &lt;em&gt;&amp;ldquo;Where should my Javascript go for MVC 6 view components?&amp;rdquo;&lt;/em&gt; &lt;a href=&#34;http://stackoverflow.com/questions/34932699/where-should-my-javascript-go-for-mvc-6-view-components/34933221#34933221&#34; target=&#34;_blank&#34;&gt;&lt;a href=&#34;http://stackoverflow.com/questions/34932699/where-should-my-javascript-go-for-mvc-6-view-components/34933221#34933221&#34;&gt;http://stackoverflow.com/questions/34932699/where-should-my-javascript-go-for-mvc-6-view-components/34933221#34933221&lt;/a&gt;&lt;/a&gt;&lt;/projectroot&gt;&lt;/string&gt;&lt;/string&gt;&lt;/string&gt;&lt;/projectroot&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;</description>
    </item>
  </channel>
</rss>
