<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="https://shazwazza.com/rss/xslt"?>
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Shazwazza</title>
    <link>https://shazwazza.com/</link>
    <description>My blog which is pretty much just all about coding</description>
    <generator>Articulate, blogging built on Umbraco</generator>
    <image>
      <url>/media/0libq25y/frog.png?rmode=max&amp;v=1da0e911f4e6890</url>
      <title>Shazwazza</title>
      <link>https://shazwazza.com/</link>
    </image>
    <item>
      <guid isPermaLink="false">1200</guid>
      <link>https://shazwazza.com/post/how-to-execute-one-controller-action-from-another-in-aspnet-5/</link>
      <category>ASP.Net</category>
      <category>Umbraco</category>
      <title>How to execute one Controller Action from another in ASP.NET 5</title>
      <description>&lt;p&gt;This will generally be a rare thing to do but if you have your reasons to do it, then this is how…&lt;/p&gt;
&lt;p&gt;In Umbraco one valid reason to do this is due to how HTTP POSTs are handled for forms. Traditionally an HTML form will POST to a specific endpoint, that endpoint will handle the validation (etc), and if all is successful it will redirect to another URL, else it will return a validation result on the current URL (i.e. PRG POST/REDIRECT/GET). In the CMS world this may end up a little bit weird because URLs are dynamic. POSTs in theory should just POST to the current URL so that if there is a validation result, this is still shown on the current URL and not a custom controller endpoint URL. This means that there can be multiple controllers handling the same URL, one for GET, another for POST and that’s exactly what Umbraco has been doing since MVC was enabled in it many years ago. For this to work, a controller is selected during the dynamic route to handle the POST (a &lt;em&gt;SurfaceController&lt;/em&gt; in Umbraco) and if successful, typically the developer will use: &lt;em&gt;return&lt;/em&gt; &lt;em&gt;RedirectToCurrentUmbracoPage&lt;/em&gt; (of type &lt;em&gt;RedirectToUmbracoPageResult&lt;/em&gt;) or if not successful will use: &lt;em&gt;return&lt;/em&gt; &lt;em&gt;CurrentUmbracoPage&lt;/em&gt; (of type &lt;em&gt;UmbracoPageResult&lt;/em&gt;). The &lt;em&gt;RedirectToUmbracoPageResult&lt;/em&gt; is easy to handle since this is just a redirect but the &lt;em&gt;UmbracoPageResult&lt;/em&gt; is a little tricky because one controller has just handled the POST request but now it wants to return a page result for the current Umbraco page which is handled by a different controller.&lt;/p&gt;
&lt;h2&gt;IActionInvoker&lt;/h2&gt;
&lt;p&gt;The concept is actually pretty simple and the &lt;em&gt;IActionInvoker&lt;/em&gt; does all of the work. You can create an &lt;em&gt;IActionInvoker&lt;/em&gt; from the &lt;em&gt;IActionInvokerFactory&lt;/em&gt; which needs an &lt;em&gt;ActionContext&lt;/em&gt;. Here’s what the &lt;em&gt;ExecuteResultAsync&lt;/em&gt; method of a custom &lt;em&gt;IActionResult&lt;/em&gt; could look like to do this:&lt;/p&gt;
&lt;pre&gt;public async Task ExecuteResultAsync(ActionContext context)
{
    // Change the route values to match the action to be executed
    context.RouteData.Values["controller"] = "Page";
    context.RouteData.Values["action"] = "Index";

    // Create a new context and excute the controller/action
    // Copy the action context - this also copies the ModelState
    var renderActionContext = new ActionContext(context)
    {
        // Normally this would be looked up via the EndpointDataSource
        // or using the IActionSelector
        ActionDescriptor = new ControllerActionDescriptor
        {
            ActionName = "Index",
            ControllerName = "Page",
            ControllerTypeInfo = typeof(PageController).GetTypeInfo(),
            DisplayName = "PageController.Index"
        }
    };

    // Get the factory
    IActionInvokerFactory actionInvokerFactory = context.HttpContext
                .RequestServices
                .GetRequiredService&amp;lt;IActionInvokerFactory&amp;gt;();

    // Create the invoker
    IActionInvoker actionInvoker = actionInvokerFactory.CreateInvoker(renderActionContext);

    // Execute!
    await actionInvoker.InvokeAsync();
}&lt;/pre&gt;
&lt;p&gt;That’s pretty must the gist of it. The note about the &lt;em&gt;ControllerActionDescriptor&lt;/em&gt; is important though, it’s probably best to not manually create these since they are already created with all of your routing. They can be queried and resolved in a few different ways such as interrogating the &lt;em&gt;EndpointDataSource&lt;/em&gt; or using the &lt;em&gt;IActionSelector&lt;/em&gt;. This execution will execute the entire pipeline for the other controller including all of it’s filters, etc…&lt;/p&gt;</description>
      <pubDate>Thu, 23 Mar 2023 15:10:18 Z</pubDate>
      <a10:updated>2023-03-23T15:10:18Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1279</guid>
      <link>https://shazwazza.com/post/allowing-dynamic-supportedcultures-in-requestlocalizationoptions/</link>
      <category>ASP.Net</category>
      <title>Allowing dynamic SupportedCultures in RequestLocalizationOptions</title>
      <description>&lt;p&gt;The documented usage of &lt;a rel="noopener" href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.requestlocalizationoptions?view=aspnetcore-5.0" target="_blank"&gt;&lt;em&gt;RequestLocalizationOptions&lt;/em&gt;&lt;/a&gt; in ASP.NET 5/Core is to assign a static list of &lt;a rel="noopener" href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.requestlocalizationoptions.supportedcultures?view=aspnetcore-5.0#Microsoft_AspNetCore_Builder_RequestLocalizationOptions_SupportedCultures" target="_blank"&gt;&lt;em&gt;SupportedCultures&lt;/em&gt;&lt;/a&gt; since ASP.NET is assuming you’ll know up-front what cultures your app is supporting. But what if you are creating a CMS or another web app that allows users to include cultures dynamically?&lt;/p&gt;
&lt;p&gt;This isn’t documented anywhere but it’s certainly possible. &lt;a rel="noopener" href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.requestlocalizationoptions.supportedcultures?view=aspnetcore-5.0#Microsoft_AspNetCore_Builder_RequestLocalizationOptions_SupportedCultures" target="_blank"&gt;&lt;em&gt;RequestLocalizationOptions.SupportedCultures&lt;/em&gt;&lt;/a&gt; is a mutable &lt;em&gt;IList&lt;/em&gt; which means that values can be added/removed at runtime if you really want.&lt;/p&gt;
&lt;h2&gt;Create a custom RequestCultureProvider&lt;/h2&gt;
&lt;p&gt;First thing you need is a custom &lt;em&gt;RequestCultureProvider&lt;/em&gt;. The trick is to pass in the &lt;em&gt;RequestLocalizationOptions&lt;/em&gt; into it’s ctor so you can dynamically modify the &lt;em&gt;SupportedCultures&lt;/em&gt; when required.&lt;/p&gt;
&lt;pre&gt;&lt;code class="lang-csharp"&gt;public class MyCultureProvider : RequestCultureProvider
{
    private readonly RequestLocalizationOptions _localizationOptions;
    private readonly object _locker = new object();

    // ctor with reference to the RequestLocalizationOptions
    public MyCultureProvider(RequestLocalizationOptions localizationOptions)
        =&amp;gt; _localizationOptions = localizationOptions;

    public override Task&amp;lt;ProviderCultureResult&amp;gt; DetermineProviderCultureResult(HttpContext httpContext)
    {
        // TODO: Implement GetCulture() to get a culture for the current request
        CultureInfo culture = GetCulture(); 

        if (culture is null)
        {
            return NullProviderCultureResult;
        }

        lock (_locker)
        {
            // check if this culture is already supported
            var cultureExists = _localizationOptions.SupportedCultures.Contains(culture);

            if (!cultureExists)
            {
                // If not, add this as a supporting culture
                _localizationOptions.SupportedCultures.Add(culture);
                _localizationOptions.SupportedUICultures.Add(culture);
            } 
        }

        return Task.FromResult(new ProviderCultureResult(culture.Name));
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Add your custom culture provider&lt;/h2&gt;
&lt;p&gt;You can configure &lt;em&gt;RequestLocalizationOptions&lt;/em&gt; in a few different ways, this example registers a custom implementation of &lt;em&gt;IConfigureOptions&amp;lt;RequestLocalizationOptions&amp;gt;&lt;/em&gt; into DI&lt;/p&gt;
&lt;pre&gt;&lt;code class="lang-csharp"&gt;public class MyRequestLocalizationOptions : IConfigureOptions&amp;lt;RequestLocalizationOptions&amp;gt;
{
    public void Configure(RequestLocalizationOptions options)
    {
        // TODO: Configure other options parameters

        // Add the custom provider,
        // in many cases you'll want this to execute before the defaults
        options.RequestCultureProviders.Insert(0, new MyCultureProvider(options));
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then just register these options: &lt;em&gt;Services.ConfigureOptions&amp;lt;MyRequestLocalizationOptions&amp;gt;();&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;That’s it, now you can have dynamic &lt;em&gt;SupportedCultures&lt;/em&gt; in your app!&lt;/p&gt;</description>
      <pubDate>Thu, 23 Mar 2023 15:10:14 Z</pubDate>
      <a10:updated>2023-03-23T15:10:14Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1293</guid>
      <link>https://shazwazza.com/post/aspnet-5-re-learning-a-few-things-part-1/</link>
      <category>ASP.Net</category>
      <title>ASP.Net 5 - Re-learning a few things (part 1)</title>
      <description>&lt;p&gt;&lt;a href="http://www.asp.net/vnext/overview/aspnet-vnext/aspnet-5-overview" target="_blank"&gt;ASP.Net 5&lt;/a&gt; (aka vNext) is now in Beta and the &lt;a href="http://www.visualstudio.com/en-us/news/vs2015-preview-vs" target="_blank"&gt;Visual Studio 2015 preview&lt;/a&gt; is now out! So, &lt;a href="http://www.asp.net/vnext/overview/aspnet-vnext/aspnet-5-overview" target="_blank"&gt;what is this new ASP.Net&lt;/a&gt;? The 2 biggest features is that it’s &lt;a href="https://github.com/aspnet" target="_blank"&gt;totally open source&lt;/a&gt; and it will support a cross platform runtime = great!! But it’s worth knowing that this is more or less a rebuild of ASP.Net and there’s quite a few things that we’ve become accustomed to that will now be totally different.&lt;/p&gt; &lt;h2&gt;Configuration files&lt;/h2&gt; &lt;p&gt;You know all of that junk in the web.config and perhaps in a bunch of other *.config files? Well that is gone! I think this is wonderful news because creating those configuration sections was a huge pain. Even better news is how easy creating custom configuration inputs will be in&amp;nbsp; ASP.Net 5 using the new &lt;u&gt;&lt;em&gt;&lt;a href="https://github.com/aspnet/Configuration/blob/dev/src/Microsoft.Framework.ConfigurationModel/IConfiguration.cs" target="_blank"&gt;IConfiguration&lt;/a&gt; &lt;/em&gt;&lt;/u&gt;and &lt;em&gt;ConfigurationModel &lt;/em&gt;sources&lt;em&gt;. &lt;/em&gt;OOTB Microsoft is releasing support for JSON, XML and INI files for configuration but of course you can easily create your own.&amp;nbsp; The repository for the configuration bits is &lt;a href="https://github.com/aspnet/Configuration" target="_blank"&gt;here&lt;/a&gt; and a nice tutorial can be found &lt;a href="http://whereslou.com/2014/05/23/asp-net-vnext-moving-parts-iconfiguration/" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;So what about configuration transforms?? That is also a thing of the past. In ASP.Net 5, “configuration” will mostly be done with code found in your Startup.cs file, anything that you want to enable in your application is done in this class. Any package that is installed in your app, you will need to opt-in to use it in your Startup.cs file. In some cases however, a configuration file might need to be updated/transformed… this could be due to an upgrade of a package. The good news is that the configuration sources in ASP.Net 5 are writable (&lt;em&gt;&lt;a href="https://github.com/aspnet/Configuration/blob/dev/src/Microsoft.Framework.ConfigurationModel/Sources/IConfigurationSource.cs#L15" target="_blank"&gt;IConfigurationSource&lt;/a&gt;&lt;/em&gt;) which means during startup or first access to your config, you could detect what needs to be updated to support your new version, make the updates in code and commit (&lt;em&gt;&lt;a href="https://github.com/aspnet/Configuration/blob/dev/src/Microsoft.Framework.ConfigurationModel/Sources/ICommitableConfigurationSource.cs" target="_blank"&gt;ICommitableConfigurationSource&lt;/a&gt;&lt;/em&gt;) the changes.&lt;/p&gt; &lt;p&gt;Wait… isn’t that going to restart the app domain??&amp;nbsp; &lt;/p&gt; &lt;p&gt;&lt;em&gt;&lt;font size="2"&gt;NOTE: If you are using IIS, there can still be a web.config which can be used to configure IIS settings under the system.webserver section.&lt;/font&gt;&lt;/em&gt;&lt;/p&gt; &lt;h2&gt;AppDomain restarts&lt;/h2&gt; &lt;p&gt;This is something that we’ve all become familiar with… you want to restart your app, just bump/touch the web.config and your app domain is restarted. This is something we’ll all have to un-learn. In ASP.Net 5 auto app domain restarts don’t happen. First, there is no web.config (or global.asax for that matter) so there are no files to bump/touch. Next, a big reason why auto app domain restarts can’t occur is because ASP.Net 5 will be able to be run on various different web servers which don’t really know about what it means to restart an app domain. For example if you’ve been playing around with vNext before you had a chance to use VS 2015, you might be familiar with the command line &lt;em&gt;“k web” &lt;/em&gt;&lt;a href="https://github.com/aspnet/Home#running-the-samples" target="_blank"&gt;(see docs for details)&lt;/a&gt;. This command will start up a simple web server: &lt;em&gt;Microsoft.AspNet.Server.WebListener&lt;/em&gt; which will serve web requests. In order for app domain restarts to occur, it would need to know how to restart itself after it’s been shutdown which isn’t exactly possible with a simple command line process. Instead if you made any changes to your code and wanted to restart your app, you’d kill the process (ctrl + c) and just call &lt;em&gt;k web&lt;/em&gt; again. Another thing to be aware of is that when you kill a process like this, your app domain does not gracefully shutdown/unwind, it’s simply terminated.&lt;/p&gt; &lt;p&gt;But not to worry! If you have a web app that requires restarting (i.e. maybe it installs plugins, etc…) and needs to gracefully unwind, it’s still possible and actually much more pleasant since you’ll be in full control of how/when it happens. In order for this to work you’ll need to be running a web server that knows how to start itself back up again - like IIS! The way to gracefully shutdown your app domain is by using: &lt;a href="https://github.com/aspnet/KRuntime/blob/dev/src/Microsoft.Framework.Runtime.Interfaces/IApplicationShutdown.cs" target="_blank"&gt;&lt;em&gt;IApplicationShutdown&lt;/em&gt;&lt;/a&gt;&lt;em&gt;&amp;nbsp;&lt;/em&gt;when you want to gracefully shutdown your app. You could even use that in combination with an &lt;a href="https://github.com/aspnet/KRuntime/blob/dev/src/Microsoft.Framework.Runtime.Interfaces/IFileWatcher.cs" target="_blank"&gt;&lt;em&gt;IFileWatcher&lt;/em&gt;&lt;/a&gt; and your own configuration files&lt;em&gt;&amp;nbsp;&lt;/em&gt;… if you really wanted to mimic an app domain restart by bumping/touching a file.&lt;/p&gt; &lt;h2&gt;Deployments, bin folder and App_Code&lt;/h2&gt; &lt;p&gt;Speaking of app domain restarts, how will ASP.Net 5 work when I put a new assembly in the /bin folder or add a new class to App_Code?? These are a couple more things that need to be un-learned. There really isn’t a /bin folder anymore (well, there is but it only contains one very special assembly if you are running IIS) and there isn’t any App_Code folder.&amp;nbsp; So where does all of this go? &lt;/p&gt; &lt;p&gt;When you publish a web project in VS 2015 (which uses &lt;em&gt;kpm pack) &lt;/em&gt;you end up with a very different looking deployment structure. There’s two folder: &lt;em&gt;approot&lt;/em&gt; and &lt;em&gt;wwwroot&lt;/em&gt;. &lt;/p&gt; &lt;p&gt;&lt;em&gt;wwwroot &lt;/em&gt;– is the content of your website, nothing more. Even things like configuration files don’t exist here, it’s just content that your webserver can serve. &lt;/p&gt; &lt;p&gt;&lt;em&gt;approot&lt;/em&gt; – this is the brains of your website. It includes all of the binaries, config files, source code, etc… that is used to run your website.&lt;/p&gt; &lt;p&gt;&lt;a href="http://weblogs.asp.net/imranbaloch/aspnet-vnext-folder-structure" target="_blank"&gt;Here’s a blog post that describes the deployed file structure&lt;/a&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Did you say source code?? Yup! By default kpm pack will deploy your site with all of it’s packages and the source code for all of your projects. The &lt;a href="http://msdn.microsoft.com/en-au/vstudio/roslyn.aspx" target="_blank"&gt;Roslyn compiler&lt;/a&gt; will take care of everything for you when your site needs to start serving requests. You can of course opt-out of this and have your site deployed as a compiled package.&lt;/p&gt; &lt;p&gt;Did you say Package?? Yup, as in Nuget package! Instead of a /bin folder full of assemblies, all of your dependencies will actually be Nuget references and stored in &lt;em&gt;approot/packages &lt;/em&gt;and if you choose to deploy your website without source, it will be compiled into a Nuget package and deployed in the packages folder as well.&lt;/p&gt; &lt;h2&gt;More to come….&lt;/h2&gt; &lt;p&gt;So there’s a a few of the things that are pretty different in ASP.Net 5, there’s still more to come and hopefully I’ll find some time to write them all up!&lt;/p&gt;</description>
      <pubDate>Thu, 23 Mar 2023 15:08:15 Z</pubDate>
      <a10:updated>2023-03-23T15:08:15Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1328</guid>
      <link>https://shazwazza.com/post/custom-assembly-loading-with-aspnet-core/</link>
      <category>ASP.Net</category>
      <title>Custom Assembly loading with Asp.Net Core</title>
      <description>&lt;p&gt;Building a plugin system in Asp.Net Core is a dream compared to previous Asp.Net versions! &lt;/p&gt; &lt;p&gt;In previous versions it was not really feasible to load Assemblies located outside of the /bin folder &lt;em&gt;&lt;u&gt;for a web application&lt;/u&gt;&lt;/em&gt;. &lt;a href="http://shazwazza.com/post/developing-a-plugin-framework-in-aspnet-with-medium-trust/" target="_blank"&gt;I battled with this concept quite a long time ago&lt;/a&gt; and although it’s sort of possible, the notion of having a plugin system that supported loading DLLs from outside of the /bin folder was riddled with hacks/problems and not really supported OOTB. &lt;/p&gt; &lt;p&gt;A large part of the issues has to do with something called an ‘Assembly Load Context’. In traditional .Net there are 3 of these context types: “&lt;strong&gt;Load&lt;/strong&gt;”, “&lt;strong&gt;LoadFrom&lt;/strong&gt;” and “&lt;strong&gt;Neither&lt;/strong&gt;”, &lt;a href="http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57143.aspx" target="_blank"&gt;here’s a very old but very relevant post about these contexts&lt;/a&gt; from Suzanne Cook. In traditional Asp.Net, the “Load” context is used as the default context and it is managed by something called &lt;em&gt;Fusion&lt;/em&gt; (.Net’s normal Assembly Loader/Binder). The problem with this context is that it is difficult to load an assembly into it that isn’t located in &lt;em&gt;Fusion’s &lt;/em&gt;probing paths (i.e. /bin folder). If you load in an Assembly with a different Assembly Load Context and then try to mix it’s Types with the Types from the default context&amp;nbsp; … you’ll quickly see that it’s not going to work. &lt;/p&gt; &lt;h2&gt;The “Neither” context&lt;/h2&gt; &lt;p&gt;Here is the Neither context definition as defined by Suzanne Cook:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;em&gt;If the user generated or found the assembly instead of Fusion, it's in neither context. This applies to assemblies loaded by Assembly.Load(byte[]) and Reflection Emit assemblies (that haven't been loaded from disk). &lt;/em&gt;&lt;a href="http://blogs.msdn.com/suzcook/archive/2003/09/19/57248.aspx"&gt;&lt;em&gt;Assembly.LoadFile()&lt;/em&gt;&lt;/a&gt;&lt;em&gt; assemblies are also generally loaded into this context, even though a path is given (because it doesn't go through Fusion).&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;In Asp.Net Core (targeting CoreCLR), the default Assembly Load Context is the “Neither” context. This is a flexible context because it doesn’t use &lt;em&gt;Fusion&lt;/em&gt; and&amp;nbsp; it allows for loading assemblies any way that you want - including loading an assembly from a byte array, from a path or by a name. Since all of Asp.Net Core uses this context it means that all of the types loaded in with this context can talk to each other without having the previous Asp.Net problems.&lt;/p&gt; &lt;p&gt;I would assume that Asp.Net Core targeting Desktop CLR would still operate the same as before and still have the 3 types of Assembly Load Context’s … Maybe someone over at Microsoft can elaborate on that one? (David Fowler… surely you know? :)&lt;/p&gt; &lt;h2&gt;Finding referenced plugin assemblies&lt;/h2&gt; &lt;p&gt;In many cases if you create a product that supports plugin types, developers will create plugins for your product and ship them via Nuget. This is a pretty standard approach since it allows developers that are using your product to install plugins from the Nuget command line or from within Visual Studio. In this case plugin types will be found in referenced assemblies to your application and will be automatically loaded. Asp.Net Core has an interface called &lt;em&gt;Microsoft.Extensions.PlatformAbstractions.ILibraryManager&lt;/em&gt; that can be used to resolve your application’s currently referenced ‘Libraries’ (i.e Nuget packages) and then each ‘Library’ returned exposes the Assemblies that it includes. Asp.Net MVC 6 has an even more helpful interface called &lt;em&gt;Microsoft.AspNet.Mvc.Infrastructure.IAssemblyProvider&lt;/em&gt; which returns a list of referenced assemblies that are filtered based on if they are assemblies that reference a subset of MVC assemblies. The default implementation of &lt;em&gt;IAssemblyProvider&lt;/em&gt; (&lt;em&gt;DefaultAssemblyProvider&lt;/em&gt;) is extensible and we can use it to override it’s property &lt;em&gt;ReferenceAssemblies&lt;/em&gt; in order to supply our own product assembly names instead of the MVC ones. This is perfect since this allows us to get a list of candidate assemblies that might contain plugins for your product:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ReferencePluginAssemblyProvider : DefaultAssemblyProvider
{
    &lt;span class="rem"&gt;//NOTE: The DefaultAssemblyProvider uses ILibraryManager to do the library/assembly querying&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; ReferencePluginAssemblyProvider(ILibraryManager libraryManager) : &lt;span class="kwrd"&gt;base&lt;/span&gt;(libraryManager)
    {
    }

    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; HashSet&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; ReferenceAssemblies 
        =&amp;gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; HashSet&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {&lt;span class="str"&gt;"MyProduct.Web"&lt;/span&gt;, &lt;span class="str"&gt;"MyProduct.Core"&lt;/span&gt;});
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;now if you want to get a list of candidate assemblies that your application is referencing you could do:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;//returns all assemblies that reference your product Assemblies&lt;/span&gt;
var candidateReferenceAssemblies = referencedPluginAssemblyProvider.CandidateAssemblies;&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;h2&gt;Finding and loading non-referenced plugin assemblies&lt;/h2&gt;
&lt;p&gt;This is where things get fun since this is the type of thing that wasn’t really very feasible with traditional Asp.Net web apps. Lets say you have a plugin framework where a plugin is installed via your web app, not in Visual Studio and therefore not directly referenced in your project. For this example, the plugin is a self contained collection of files and folders which could consist of: Css, JavaScript, Razor Views, and Assemblies. This plugin model is pretty nice since to install the plugin would mean just dropping the plugin folder into the right directory in your app and similarly&amp;nbsp; to uninstall it you can just remove the folder.&amp;nbsp; The first step is to be able to load in these plugin Assemblies from custom locations. For an example, let’s assume the web app has the following folder structure:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;App Root 
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;App_Plugins &lt;/strong&gt;&lt;em&gt;&amp;lt;—This will be the directory that contains plugin folders&lt;/em&gt; 
&lt;ul&gt;
&lt;li&gt;MyPlugin1 
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;bin &lt;/strong&gt;&lt;em&gt;&amp;lt;—by convention we’ll search for Assemblies in the /bin folder inside of a plugin&lt;/em&gt; 
&lt;li&gt;Views&lt;/li&gt;&lt;/ul&gt;
&lt;li&gt;MyPlugin2 
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;bin&lt;em&gt; &lt;/em&gt;&lt;/strong&gt;&lt;em&gt;&amp;lt;—by convention we’ll search for Assemblies in the /bin folder inside of a plugin&lt;/em&gt; 
&lt;li&gt;css&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;li&gt;Views 
&lt;li&gt;&lt;em&gt;wwwroot&lt;/em&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;h3&gt;IAssemblyLoader&lt;/h3&gt;
&lt;p&gt;The first thing we need is an ‘&lt;em&gt;Microsoft.Extensions.PlatformAbstractions.IAssemblyLoader&lt;/em&gt;’, this is the thing that will do the assembly loading into the Assembly Load Context based on an &lt;em&gt;AssemblyName &lt;/em&gt;and a location of a DLL:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; DirectoryLoader : IAssemblyLoader
{
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; IAssemblyLoadContext _context;
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; DirectoryInfo _path;

    &lt;span class="kwrd"&gt;public&lt;/span&gt; DirectoryLoader(DirectoryInfo path, IAssemblyLoadContext context)
    {
        _path = path;
        _context = context;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; Assembly Load(AssemblyName assemblyName)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; _context.LoadFile(Path.Combine(_path.FullName, assemblyName.Name + &lt;span class="str"&gt;".dll"&lt;/span&gt;));
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; IntPtr LoadUnmanagedLibrary(&lt;span class="kwrd"&gt;string&lt;/span&gt; name)
    {
        &lt;span class="rem"&gt;//this isn't going to load any unmanaged libraries, just throw&lt;/span&gt;
        &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; NotImplementedException();
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;h3&gt;IAssemblyProvider&lt;/h3&gt;
&lt;p&gt;Next up we’ll need a custom &lt;em&gt;IAssemblyProvider&lt;/em&gt; but instead of using the one MVC ships with, this one will be totally custom in order to load and resolve the assemblies based on the plugin’s /bin folders. The following code should be pretty straight forward, the &lt;em&gt;CandidateAssemblies&lt;/em&gt; property iterates over each found /bin folder inside of a plugin’s folder inside of App_Plugins. For each /bin folder found it creates a &lt;em&gt;DirectoryLoader &lt;/em&gt;mentioned above and loads in each DLL found by it’s &lt;em&gt;AssemblyName&lt;/em&gt; into the current Assembly Load Context.&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;/// This will return assemblies found in App_Plugins plugin's /bin folders&lt;/span&gt;
&lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CustomDirectoryAssemblyProvider : IAssemblyProvider
{
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; IFileProvider _fileProvider;
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; IAssemblyLoadContextAccessor _loadContextAccessor;
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; IAssemblyLoaderContainer _assemblyLoaderContainer;

    &lt;span class="kwrd"&gt;public&lt;/span&gt; CustomDirectoryAssemblyProvider(
            IFileProvider fileProvider, 
            IAssemblyLoadContextAccessor loadContextAccessor, 
            IAssemblyLoaderContainer assemblyLoaderContainer)
    {
        _fileProvider = fileProvider;
        _loadContextAccessor = loadContextAccessor;
        _assemblyLoaderContainer = assemblyLoaderContainer;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; IEnumerable&amp;lt;Assembly&amp;gt; CandidateAssemblies
    {
        get
        {
            var content = _fileProvider.GetDirectoryContents(&lt;span class="str"&gt;"/App_Plugins"&lt;/span&gt;);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (!content.Exists) &lt;span class="kwrd"&gt;yield&lt;/span&gt; &lt;span class="kwrd"&gt;break&lt;/span&gt;;
            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var pluginDir &lt;span class="kwrd"&gt;in&lt;/span&gt; content.Where(x =&amp;gt; x.IsDirectory))
            {
                var binDir = &lt;span class="kwrd"&gt;new&lt;/span&gt; DirectoryInfo(Path.Combine(pluginDir.PhysicalPath, &lt;span class="str"&gt;"bin"&lt;/span&gt;));
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (!binDir.Exists) &lt;span class="kwrd"&gt;continue&lt;/span&gt;;
                &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var assembly &lt;span class="kwrd"&gt;in&lt;/span&gt; GetAssembliesInFolder(binDir))
                {
                    &lt;span class="kwrd"&gt;yield&lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; assembly;
                }
            }
        }
    }

    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// Returns assemblies loaded from /bin folders inside of App_Plugins&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;param name="binPath"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;private&lt;/span&gt; IEnumerable&amp;lt;Assembly&amp;gt; GetAssembliesInFolder(DirectoryInfo binPath)
    {
        &lt;span class="rem"&gt;// Use the default load context&lt;/span&gt;
        var loadContext = _loadContextAccessor.Default;

        &lt;span class="rem"&gt;// Add the loader to the container so that any call to Assembly.Load &lt;/span&gt;
        &lt;span class="rem"&gt;// will call the load context back (if it's not already loaded)&lt;/span&gt;
        &lt;span class="kwrd"&gt;using&lt;/span&gt; (_assemblyLoaderContainer.AddLoader(
            &lt;span class="kwrd"&gt;new&lt;/span&gt; DirectoryLoader(binPath, loadContext)))
        {
            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var fileSystemInfo &lt;span class="kwrd"&gt;in&lt;/span&gt; binPath.GetFileSystemInfos(&lt;span class="str"&gt;"*.dll"&lt;/span&gt;))
            {
                &lt;span class="rem"&gt;//// In theory you should be able to use Assembly.Load() here instead&lt;/span&gt;
                &lt;span class="rem"&gt;//var assembly1 = Assembly.Load(AssemblyName.GetAssemblyName(fileSystemInfo.FullName));&lt;/span&gt;
                var assembly2 = loadContext.Load(AssemblyName.GetAssemblyName(fileSystemInfo.FullName));
                &lt;span class="kwrd"&gt;yield&lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; assembly2;
            }
        }
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;That’s pretty much it! If you have an instance of &lt;em&gt;CustomDirectoryAssemblyProvider&lt;/em&gt; then you can get Assembly references to all of the assemblies found in App_Plugins:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;//returns all plugin assemblies found in App_Plugins&lt;/span&gt;
var candidatePluginAssemblies = customDirectoryAssemblyProvider.CandidateAssemblies;&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;h2&gt;Integrating non-referenced plugins/Assemblies with MVC&lt;/h2&gt;
&lt;p&gt;What if you had custom plugin types as MVC Controllers or other MVC types? By default MVC only knows about assemblies that your project has references to based on the &lt;em&gt;DefaultAssemblyLoader&lt;/em&gt;.&amp;nbsp; If we wanted MVC to know about Controllers that exist in a plugin not referenced by your project (i.e. in App_Plugins) then it’s a case of registering a custom &lt;em&gt;IAssemblyProvider&lt;/em&gt; in IoC which will get resolved by MVC. To make this super flexible we can create a custom &lt;em&gt;IAssemblyProvider&lt;/em&gt; that wraps multiple other ones and allows you to pass in a custom &lt;em&gt;referenceAssemblies&lt;/em&gt; filter if you wanted to use this to resolve your own plugin types:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CompositeAssemblyProvider : DefaultAssemblyProvider
{
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; IAssemblyProvider[] _additionalProviders;
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;[] _referenceAssemblies;

    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// Constructor&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;param name="libraryManager"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;param name="additionalProviders"&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// If passed in will concat the assemblies returned from these &lt;/span&gt;
    &lt;span class="rem"&gt;/// providers with the default assemblies referenced&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/param&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;param name="referenceAssemblies"&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// If passed in it will filter the candidate libraries to ones&lt;/span&gt;
    &lt;span class="rem"&gt;/// that reference the assembly names passed in. &lt;/span&gt;
    &lt;span class="rem"&gt;/// (i.e. "MyProduct.Web", "MyProduct.Core" )&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/param&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; CompositeAssemblyProvider(
        ILibraryManager libraryManager,
        IAssemblyProvider[] additionalProviders = &lt;span class="kwrd"&gt;null&lt;/span&gt;,
        &lt;span class="kwrd"&gt;string&lt;/span&gt;[] referenceAssemblies = &lt;span class="kwrd"&gt;null&lt;/span&gt;) : &lt;span class="kwrd"&gt;base&lt;/span&gt;(libraryManager)
    {
        _additionalProviders = additionalProviders;
        _referenceAssemblies = referenceAssemblies;
    }

    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// Uses the default filter if a custom list of reference&lt;/span&gt;
    &lt;span class="rem"&gt;/// assemblies has not been provided&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; HashSet&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; ReferenceAssemblies
        =&amp;gt; _referenceAssemblies == &lt;span class="kwrd"&gt;null&lt;/span&gt;
            ? &lt;span class="kwrd"&gt;base&lt;/span&gt;.ReferenceAssemblies
            : &lt;span class="kwrd"&gt;new&lt;/span&gt; HashSet&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(_referenceAssemblies);
    
    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// Returns the base Libraries referenced along with any DLLs/Libraries&lt;/span&gt;
    &lt;span class="rem"&gt;/// returned from the custom IAssemblyProvider passed in&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; IEnumerable&amp;lt;Library&amp;gt; GetCandidateLibraries()
    {
        var baseCandidates = &lt;span class="kwrd"&gt;base&lt;/span&gt;.GetCandidateLibraries();
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (_additionalProviders == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;return&lt;/span&gt; baseCandidates;
        &lt;span class="kwrd"&gt;return&lt;/span&gt; baseCandidates               
            .Concat(
            _additionalProviders.SelectMany(provider =&amp;gt; provider.CandidateAssemblies.Select(
                x =&amp;gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Library(x.FullName, &lt;span class="kwrd"&gt;null&lt;/span&gt;, Path.GetDirectoryName(x.Location), &lt;span class="kwrd"&gt;null&lt;/span&gt;, Enumerable.Empty&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(),
                    &lt;span class="kwrd"&gt;new&lt;/span&gt;[] { &lt;span class="kwrd"&gt;new&lt;/span&gt; AssemblyName(x.FullName) }))));
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;To register this in IoC you just need to make sure it’s registered after you register MVC so that it overrides the last registered &lt;em&gt;IAssemblyProvider&lt;/em&gt;:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;//Add MVC services&lt;/span&gt;
services.AddMvc();
&lt;span class="rem"&gt;//Replace the default IAssemblyProvider with the composite one&lt;/span&gt;
services.AddSingleton&amp;lt;IAssemblyProvider, CompositeAssemblyProvider&amp;gt;(provider =&amp;gt;
{
    &lt;span class="rem"&gt;//create the custom plugin directory provider&lt;/span&gt;
    var hosting = provider.GetRequiredService&amp;lt;IApplicationEnvironment&amp;gt;();
    var fileProvider = &lt;span class="kwrd"&gt;new&lt;/span&gt; PhysicalFileProvider(hosting.ApplicationBasePath);
    var pluginAssemblyProvider = &lt;span class="kwrd"&gt;new&lt;/span&gt; CustomDirectoryAssemblyProvider(
        fileProvider,         
        PlatformServices.Default.AssemblyLoadContextAccessor,
        PlatformServices.Default.AssemblyLoaderContainer);
    &lt;span class="rem"&gt;//return the composite one - this wraps the default MVC one&lt;/span&gt;
    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; CompositeAssemblyProvider(
        provider.GetRequiredService&amp;lt;ILibraryManager&amp;gt;(),
        &lt;span class="kwrd"&gt;new&lt;/span&gt; IAssemblyProvider[] {pluginAssemblyProvider});
});&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Your all set! Now you have the ability to load in Assemblies from any location you want, you could even load them in as byte array’s from an external data source.&amp;nbsp; What’s great about all of this is that it just works and you can integrate these external Assemblies into MVC. &lt;/p&gt;
&lt;p&gt;Some things worth noting:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Parts of the assembly loading APIs are changing a bit in Asp.Net Core RC2: &lt;a title="https://github.com/aspnet/Announcements/issues/149" href="https://github.com/aspnet/Announcements/issues/149"&gt;https://github.com/aspnet/Announcements/issues/149&lt;/a&gt; 
&lt;li&gt;The above code doesn’t take into account what happens if you load in the same Assembly from multiple locations. In this case, the last one in wins/is active AFAIK – I haven’t tested this yet but I’m pretty sure that’s how it works. 
&lt;li&gt;You may have some issues if load in the same Assembly more than once from multiple locations if those Assemblies have different strong names, or major versions applied to them – I also haven’t tested this yet&lt;/li&gt;&lt;/ul&gt;</description>
      <pubDate>Thu, 23 Mar 2023 15:08:15 Z</pubDate>
      <a10:updated>2023-03-23T15:08:15Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1171</guid>
      <link>https://shazwazza.com/post/appveyor-and-aspnet-core-previously-aspnet-5/</link>
      <category>ASP.Net</category>
      <title>AppVeyor and ASP.Net Core (Previously ASP.Net 5)</title>
      <description>&lt;p&gt;Last year I created a runtime Js/Css pre-processor for ASP.Net Core (Previously ASP.Net 5) called “&lt;a href="https://github.com/Shazwazza/Smidge" target="_blank"&gt;Smidge&lt;/a&gt;” and have been meaning to blog about how I integrated this with AppVeyor – to run my tests, build the project and output the Nuget files I need, so here it goes…&lt;/p&gt; &lt;h2&gt;The build script&lt;/h2&gt; &lt;p&gt;I use Powershell for my build scripts for my projects since it’s reasonably easy to read and the same script format has worked quite well for ASP.Net Core projects too. You can see the whole build file &lt;a href="https://github.com/Shazwazza/Smidge/blob/master/build.ps1" target="_blank"&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt;. Here’s the important things to note:&lt;/p&gt; &lt;p&gt;With AppVeyor (and probably other build servers), you need to ensure that it actually has the dnx version you need: &lt;/p&gt;&lt;pre class="csharpcode"&gt;# ensure the correct version
&amp;amp; $DNVM install 1.0.0-rc1-update1&lt;/pre&gt;
&lt;p&gt;Next you need to make sure that the current process is using the version you need to build:&lt;/p&gt;&lt;pre class="csharpcode"&gt;# use the correct version
&amp;amp; $DNVM use 1.0.0-rc1-update1&lt;/pre&gt;
&lt;p&gt;Then we need to use DNU to make sure that your project has everything it needs to build:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&amp;amp; $DNU restore &lt;span class="str"&gt;"$ProjectJsonPath"&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Lastly it’s just building and packaging the project:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&amp;amp; $DNU build &lt;span class="str"&gt;"$ProjectJsonPath"&lt;/span&gt;
&amp;amp; $DNU pack &lt;span class="str"&gt;"$ProjectJsonPath"&lt;/span&gt; --configuration Release --&lt;span class="kwrd"&gt;out&lt;/span&gt; &lt;span class="str"&gt;"$ReleaseFolder"&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The rest of the build file is normal Powershell bits. &lt;/p&gt;
&lt;h2&gt;The test script&lt;/h2&gt;
&lt;p&gt;I’m using xunit for unit tests in this project and similarly to the build script I’m using a simple Powershell script to execute the tests on the build server, the test runner file is &lt;a href="https://github.com/Shazwazza/Smidge/blob/master/tests.ps1" target="_blank"&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt;. The important parts are just like the above: Ensure the correct version is installed and being used by the current process and making sure that the project has everything it needs to build and finally to build it. The last missing piece is to actually run the tests:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&amp;amp; $DNX -p &lt;span class="str"&gt;"$TestsFolder"&lt;/span&gt; test&lt;/pre&gt;
&lt;p&gt;Where ‘&lt;em&gt;test’&lt;/em&gt; is a command defined in my &lt;a href="https://github.com/Shazwazza/Smidge/blob/master/tests/Smidge.Tests/project.json#L10" target="_blank"&gt;project.json as part of my unit test project&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;AppVeyor configuration&lt;/h2&gt;
&lt;p&gt;The good news is that there’s really not a lot to setup, it’s super easy. In your AppVeyor settings just go to the ‘Build’ section and tell it to execute the Powershell script with its build version information:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://shazwazza.com/media/articulate/windows-live-writer-smidge-rc3-released_eb4d-image_2.png"&gt;&lt;img title="image" style="display: inline" alt="image" src="http://shazwazza.com/media/articulate/windows-live-writer-smidge-rc3-released_eb4d-image_thumb.png" width="600" height="208"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Then for the unit tests is basically the same, click on the ‘Tests’ section and tell it to execute the Powershell test script:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://shazwazza.com/media/articulate/windows-live-writer-smidge-rc3-released_eb4d-image_4.png"&gt;&lt;img title="image" style="display: inline" alt="image" src="http://shazwazza.com/media/articulate/windows-live-writer-smidge-rc3-released_eb4d-image_thumb_1.png" width="600" height="222"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And that’s pretty much it! The only other part I’ve had to setup is the paths to my Artifacts (Nuget files) based on the current build number.&lt;/p&gt;
&lt;p&gt;Now whenever I commit, AppVeyor will execute the build script and test script and we can see the output:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://shazwazza.com/media/articulate/windows-live-writer-smidge-rc3-released_eb4d-image_6.png"&gt;&lt;img title="image" style="display: inline" alt="image" src="http://shazwazza.com/media/articulate/windows-live-writer-smidge-rc3-released_eb4d-image_thumb_2.png" width="600" height="238"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And it’s smart enough to know that the test runner executed is for unit tests, so all the unit test output shows up in the ‘Tests’ tab of the build&lt;/p&gt;
&lt;p&gt;&lt;a href="http://shazwazza.com/media/articulate/windows-live-writer-smidge-rc3-released_eb4d-image_8.png"&gt;&lt;img title="image" style="display: inline" alt="image" src="http://shazwazza.com/media/articulate/windows-live-writer-smidge-rc3-released_eb4d-image_thumb_3.png" width="600" height="152"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now that that’s all setup, AppVeyor even gives you a handy Nuget feed that you can use to test your packages based on each build, this can be configured on the ‘NuGet’ settings section, for example here’s the Smidge feed: &lt;a title="https://ci.appveyor.com/nuget/smidge" href="https://ci.appveyor.com/nuget/smidge"&gt;https://ci.appveyor.com/nuget/smidge&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Smidge 1.0.0-RC3&lt;/h2&gt;
&lt;p&gt;It’s worth noting that I’ve also released a new version of Smidge since I finally had some time to work on it. Couple of bugs fixed in this release and also a handy new feature too! You can see the release notes here: &lt;a title="https://github.com/Shazwazza/Smidge/releases/tag/1.0.0-rc3" href="https://github.com/Shazwazza/Smidge/releases/tag/1.0.0-rc3"&gt;https://github.com/Shazwazza/Smidge/releases/tag/1.0.0-rc3&lt;/a&gt;.&amp;nbsp; I’ve also updated a lot of the documentation, the main readme file was getting quite long so I’ve moved all of the docs over to the project’s Wiki on GitHub and condensed the readme for the most important bits. Have a look here: &lt;a title="https://github.com/Shazwazza/Smidge/releases/tag/1.0.0-rc3" href="https://github.com/Shazwazza/Smidge/releases/tag/1.0.0-rc3"&gt;https://github.com/Shazwazza/Smidge&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 23 Mar 2023 15:08:15 Z</pubDate>
      <a10:updated>2023-03-23T15:08:15Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1184</guid>
      <link>https://shazwazza.com/post/model-binding-with-fromservices-in-aspnet-5/</link>
      <category>ASP.Net</category>
      <title>Model binding with FromServices in ASP.Net 5</title>
      <description>&lt;p&gt;Here’s a new nifty feature I found in ASP.Net 5 – you can construct your model during model binding with IoC without any additional work. This is available on the dev branch on GitHub and is based on something called &lt;a href="https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.Core/ModelBinders/ServicesModelBinder.cs" target="_blank"&gt;&lt;em&gt;ServicesModelBinder&lt;/em&gt;&lt;/a&gt;. This is actually pretty cool because it means that you can have a model wired up with all of it’s dependencies based on IoC and then bound to your controller action’s parameters.&lt;/p&gt; &lt;h2&gt;FromServices attribute&lt;/h2&gt; &lt;p&gt;There’s a new attribute called &lt;a href="https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.ModelBinding/BinderMetadata/FromServicesAttribute.cs" target="_blank"&gt;&lt;em&gt;FromServices&lt;/em&gt;&lt;/a&gt; which is what you use to enable this functionality. For example:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; async Task&amp;lt;ActionResult&amp;gt; GetProduct(
    [FromServices]ProductModel product)
{

}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;What this attribute does is tell MVC to bind the model using &lt;a href="https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.ModelBinding/BinderMetadata/IServiceActivatorBinderMetadata.cs" target="_blank"&gt;&lt;em&gt;IServiceActivatorBinderMetadata&lt;/em&gt;&lt;/a&gt; which is what the &lt;em&gt;FromServices&lt;/em&gt; attribute implements. This in turn tells MVC to lookup the model binder that is aware of &lt;em&gt;IServiceActivatorBinderMetadata &lt;/em&gt;which happens to be the &lt;em&gt;ServicesModelBinder.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;ServicesModelBinder&lt;/h2&gt;
&lt;p&gt;This model binder is pretty simple, it’s just going to resolve the model type from your IoC container. That could be pretty useful if you need to build up your model properties based on other services. I think some people might argue that this isn’t great practice because this is putting the binding logic in to the model itself instead of using a separate class to perform the binding logic. I suppose it’s up to the individual developer as to what their preference is. You can of course still create your own &lt;em&gt;&lt;a href="https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.ModelBinding/Binders/IModelBinder.cs" target="_blank"&gt;IModelBinder&lt;/a&gt;&lt;/em&gt; and use the &lt;em&gt;&lt;a href="https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.ModelBinding/BinderMetadata/ModelBinderAttribute.cs" target="_blank"&gt;ModelBinderAttribute&lt;/a&gt;&lt;/em&gt; to keep the model binding logic in the binder itself.&lt;/p&gt;
&lt;h2&gt;Incoming route values&lt;/h2&gt;
&lt;p&gt;Since the model is being created from IoC, how do you get the current route values to build up your model? To do that you’d put a constructor dependency on &lt;em&gt;IContextAccessor&amp;lt;ActionContext&amp;gt;. &lt;/em&gt;This will give you all of the current route values, &lt;em&gt;HttpContext&lt;/em&gt;, etc… basically everything you’d need to pull the data out of the current request to build your model. &lt;/p&gt;
&lt;h2&gt;Example&lt;/h2&gt;
&lt;p&gt;Given the above GetProduct example, the &lt;em&gt;ProductModel&lt;/em&gt; class could look like:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ProductModel
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; ProductModel(IContextAccessor&amp;lt;ActionContext&amp;gt; action, IProductService prodService)
    {
        &lt;span class="rem"&gt;//TODO: Do some error checking...&lt;/span&gt;
        var productId = action.Value.RouteData.Values[&lt;span class="str"&gt;"product"&lt;/span&gt;];
        Value = prodService.Get(productId);
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; IProduct Value { get; &lt;span class="kwrd"&gt;private&lt;/span&gt; set; }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;This is pretty simple – the &lt;em&gt;IProduct&lt;/em&gt; is looked up from the &lt;em&gt;IProductService&lt;/em&gt; based on the incoming ‘product’ route value. Then in the controller you could just do: &lt;em&gt;product.Value&lt;/em&gt; to get the value for &lt;em&gt;IProduct&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;You then need to ensure that both IProductService and ProductModel are registered as services in your container and it’s really important that the &lt;em&gt;ProductModel&lt;/em&gt; is registered as a Transient object &lt;/p&gt;</description>
      <pubDate>Thu, 23 Mar 2023 15:08:15 Z</pubDate>
      <a10:updated>2023-03-23T15:08:15Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1191</guid>
      <link>https://shazwazza.com/post/aspnet-5-re-learning-a-few-things-part-2/</link>
      <category>ASP.Net</category>
      <title>ASP.Net 5 Re-learning a few things (part 2)</title>
      <description>&lt;p&gt;This is part 2 of a series of posts about some fundamental changes in ASP.Net 5 that we’ll need to re-learn (or un-learn!)&lt;/p&gt; &lt;p&gt;Part 1: &lt;a title="http://shazwazza.com/post/aspnet-5-re-learning-a-few-things-part-1/" href="http://shazwazza.com/post/aspnet-5-re-learning-a-few-things-part-1/"&gt;http://shazwazza.com/post/aspnet-5-re-learning-a-few-things-part-1/&lt;/a&gt;&lt;/p&gt; &lt;h2&gt;System.Web&lt;/h2&gt; &lt;p&gt;This probably isn’t new news to most people since it’s really one of the fundamental shifts for ASP.Net 5 – There won’t be a System.Web DLL. Everything that you’ll install in your website will come as different, smaller, separate libraries. For example, if you want to serve static files, you’d reference the &lt;em&gt;Microsoft.AspNet.StaticFiles&lt;/em&gt; package, if you want to use MVC, you’d include the &lt;em&gt;Microsoft.AspNet.Mvc &lt;/em&gt;package&lt;em&gt;.&lt;/em&gt; &lt;/p&gt; &lt;p&gt;ASP.Net 5: “&lt;a href="http://www.asp.net/vnext/overview/aspnet-vnext/aspnet-5-overview" target="_blank"&gt;consists of modular components with minimal overhead, so you retain flexibility while constructing your solutions&lt;/a&gt;”&lt;/p&gt; &lt;h2&gt;Web Forms&lt;/h2&gt; &lt;p&gt;Gone! YAY! :-)&lt;/p&gt; &lt;p&gt;Web Forms will still be a part of .Net as part of the main framework in System.Web, just not part of ASP.Net 5. &lt;/p&gt; &lt;h2&gt;HttpModules &lt;/h2&gt; &lt;p&gt;An HttpModule simply doesn’t exist in Asp.Net 5, but of course there is a new/better way to achieve this functionality, it’s called Middleware. In an HttpModule, you had to execute code based on the various &lt;a href="http://msdn.microsoft.com/en-us/library/bb470252.aspx" target="_blank"&gt;stages&lt;/a&gt; of a request, things such as &lt;em&gt;AuthenticateRequest, AuthorizeRequest, PostResolveRequestCache&lt;/em&gt;, and other slightly confusingly named events. This is no longer the case with Middleware, things just make sense now … everything is simply a linear execution of your code. You can have multiple middleware’s defined to execute in your application and each one is registered explicitly in your Startup.cs file. As a developer, you are in full control of what get’s executed and in what order instead of not knowing which HttpModules are executing and not really in control of their order of execution. Middleware can simply modify a request and continue calling the next one in the chain, or it can just terminate the pipeline and return a result. &lt;/p&gt; &lt;p&gt;There’s loads of examples in the source for middleware, ranging from the &lt;a href="https://github.com/aspnet/StaticFiles/blob/dev/src/Microsoft.AspNet.StaticFiles/StaticFileMiddleware.cs" target="_blank"&gt;static file middleware&lt;/a&gt; to &lt;a href="https://github.com/aspnet/Security/blob/master/src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationMiddleware.cs" target="_blank"&gt;cookie authentication middleware&lt;/a&gt;,&amp;nbsp; etc…&lt;/p&gt; &lt;p&gt;And &lt;a href="http://whereslou.com/2014/05/28/asp-net-moving-parts-ibuilder/" target="_blank"&gt;here’s a good article&lt;/a&gt; that explains middeware registration and the flow of control.&lt;/p&gt; &lt;h2&gt;HttpHandlers&lt;/h2&gt; &lt;p&gt;HttpHandlers are also a thing of the past. All they really were was a request handler that was based on a specific request path. MVC (which now also includes WebApi) has got this covered. If you really wanted, you could create middleware for this type of functionality as well but unless you require something extraordinarily complex that MVC cannot do (and it can do a lot!), I’d recommend just sticking with MVC.&lt;/p&gt;</description>
      <pubDate>Thu, 23 Mar 2023 15:08:15 Z</pubDate>
      <a10:updated>2023-03-23T15:08:15Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1232</guid>
      <link>https://shazwazza.com/post/using-aspnet5-optionsmodel/</link>
      <category>ASP.Net</category>
      <category>Web Development</category>
      <title>Using AspNet5 OptionsModel</title>
      <description>&lt;p&gt;If you’ve used AspNet5 then you’ve probably been using some MVC, in which case you’ve probably seen something like this in your Startup class:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;// Add MVC services to the services container&lt;/span&gt;
services.AddMvc(configuration)
    .Configure&amp;lt;MvcOptions&amp;gt;(options =&amp;gt;
    {
        &lt;span class="rem"&gt;//Configure some MVC options like customizing the &lt;/span&gt;
        &lt;span class="rem"&gt;// view engines, etc...&lt;/span&gt;
        options.ViewEngines.Insert(0, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(TestViewEngine));
    });&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;It turns out this syntax for specifying ‘options’ for a given service is a generic pattern that you can use in your own code. In fact the OptionsModel framework is it’s own code repository: &lt;a title="https://github.com/aspnet/Options" href="https://github.com/aspnet/Options"&gt;https://github.com/aspnet/Options&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I’ve implemented custom options in my AspNet5 project called &lt;a href="https://github.com/Shazwazza/smidge" target="_blank"&gt;Smidge&lt;/a&gt; (a runtime JavaScript/CSS pre-processing engine) and wanted to share the details since as far as I’ve seen there isn’t any documentation about this.&lt;/p&gt;
&lt;h2&gt;What are options?&lt;/h2&gt;
&lt;p&gt;Probably the simplest way to describe the options framework is that: Options allow you to configure your application via code during startup.&lt;/p&gt;
&lt;p&gt;Options are just a POCO class that can contain configuration options to customize the behavior of your library. These option classes can be injected into any of your services with IoC using an interface called &lt;em&gt;&lt;a href="https://github.com/aspnet/Options/blob/dev/src/Microsoft.Framework.OptionsModel/IOptions.cs" target="_blank"&gt;Microsoft.Framework.OptionsModel.IOptions&lt;/a&gt;&lt;/em&gt;. There’s a caveat to this POCO class however: It must contain an parameter-less/empty constructor which means you cannot have services injected into the your options class via it’s constructor.&amp;nbsp; This options framework also allows for ‘named’ options. So for example, perhaps you have a single options class that you would like to have configured in 2 different ways, one for ‘staging’ and one for your ‘live’ website.&lt;/p&gt;
&lt;h2&gt;Creating options&lt;/h2&gt;
&lt;p&gt;Here’s a really simple example of a POCO options class:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CustomMessageOptions
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; CustomMessage()
    {
        Message = &lt;span class="str"&gt;""&lt;/span&gt;;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Message { get; set; }
}&lt;/pre&gt;
&lt;p&gt;In order to use this options class you need to create an options configuration class. For example:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CustomMessageOptionsSetup : ConfigureOptions&amp;lt;CustomMessageOptions&amp;gt;
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; CustomMessageOptionsSetup() 
    : &lt;span class="kwrd"&gt;base&lt;/span&gt;(ConfigureMessageOptions)
    {
    }

    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// Set the default options&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ConfigureMessageOptions(CustomMessageOptions options)
    {
        options.Message = &lt;span class="str"&gt;"Hello world"&lt;/span&gt;;
    }
}&lt;/pre&gt;
&lt;p&gt;Then you need to add this class to your IoC container of type &lt;a href="https://github.com/aspnet/Options/blob/dev/src/Microsoft.Framework.OptionsModel/IConfigureOptions.cs" target="_blank"&gt;&lt;em&gt;Microsoft.Framework.OptionsModel.IConfigureOptions&lt;/em&gt;&lt;/a&gt;:&lt;/p&gt;&lt;pre class="csharpcode"&gt;services.AddTransient&amp;lt;IConfigureOptions&amp;lt;CustomMessageOptions&amp;gt;, CustomMessageOptionsSetup&amp;gt;();&lt;/pre&gt;
&lt;h2&gt;Using options&lt;/h2&gt;
&lt;p&gt;To configure your options during startup, you do so in the &lt;em&gt;ConfigureServices &lt;/em&gt;method like:&lt;/p&gt;&lt;pre class="csharpcode"&gt;services.Configure&amp;lt;CustomMessageOptions&amp;gt;(options =&amp;gt;
{
    options.Message = &lt;span class="str"&gt;"Hello there!"&lt;/span&gt;;
});&lt;/pre&gt;
&lt;p&gt;Now you can have these options injected into any of your services using the &lt;em&gt;IOptions&lt;/em&gt; interface noted previously:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MyCoolService 
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; MyCoolService(IOptions&amp;lt;CustomMessageOptions&amp;gt; messageOptions)
    {
        &lt;span class="rem"&gt;//IOptions exposes an 'Options' property which resolves an instance&lt;/span&gt;
        &lt;span class="rem"&gt;//of CustomMessageOptions&lt;/span&gt;
        ConfiguredMessage = messageOptions.Options.Message;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ConfiguredMessage {get; &lt;span class="kwrd"&gt;private&lt;/span&gt; set;}
}&lt;/pre&gt;
&lt;h2&gt;Named options&lt;/h2&gt;
&lt;p&gt;As an example, lets say that you want a different message configured for your ‘staging’ and ‘live’ websites. This can be done with named options, here’s an example:&lt;/p&gt;&lt;pre class="csharpcode"&gt;services
    .Configure&amp;lt;CustomMessageOptions&amp;gt;(options =&amp;gt;
    {
        options.Message = &lt;span class="str"&gt;"Hi! This is the staging site"&lt;/span&gt;;
    }, &lt;span class="str"&gt;"staging"&lt;/span&gt;)
    .Configure&amp;lt;CustomMessageOptions&amp;gt;(options =&amp;gt;
    {
        options.Message = &lt;span class="str"&gt;"Hi! This is the live site"&lt;/span&gt;;
    }, &lt;span class="str"&gt;"live"&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Then in your service you can resolve the option instance by name:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MyCoolService 
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; MyCoolService(IOptions&amp;lt;CustomMessageOptions&amp;gt; messageOptions)
    {
        &lt;span class="rem"&gt;//IRL This value would probably be set via some environment variable&lt;/span&gt;
        var configEnvironment = &lt;span class="str"&gt;"staging"&lt;/span&gt;;

        &lt;span class="rem"&gt;//IOptions exposes an 'GetNamedOptions' method which resolves an instance&lt;/span&gt;
        &lt;span class="rem"&gt;//of CustomMessageOptions based on a defined named configuration&lt;/span&gt;
        ConfiguredMessage = messageOptions.GetNamedOptions(configEnvironment);
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ConfiguredMessage {get; &lt;span class="kwrd"&gt;private&lt;/span&gt; set;}
}&lt;/pre&gt;
&lt;h2&gt;Configuring options with other services&lt;/h2&gt;
&lt;p&gt;Since your options class is just a POCO object and must have a parameter-less/empty constructor, you cannot inject services into the options class. However, there is a way to use IoC services in your options classes by customizing the &lt;em&gt;ConfigureOptions&lt;/em&gt; class created above.&amp;nbsp; In many cases this won’t be necessary but this really depends on how you are using options.&amp;nbsp; As a (bad) example, lets say we wanted to expose a custom helper service called SiteHelper on the &lt;em&gt;CustomMessageOptions&lt;/em&gt; class that can be used by a developer to create the message. The end result syntax might look like:&lt;/p&gt;&lt;pre class="csharpcode"&gt;services.Configure&amp;lt;CustomMessageOptions&amp;gt;(options =&amp;gt;
    {
        var siteId = options.SiteHelper.GetSiteId();
        options.Message = &lt;span class="str"&gt;"Hi! This is the staging site with id: "&lt;/span&gt; + siteId;
    });&lt;/pre&gt;
&lt;p&gt;In order for that to work the &lt;em&gt;options.SiteHelper&lt;/em&gt; property needs to be initialized. This is done with the &lt;em&gt;CustomMessageOptionsSetup &lt;/em&gt;class (created above) which has been added to the IoC container, this means it can have other services injected into it. The resulting class would look like:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CustomMessageOptionsSetup : ConfigureOptions&amp;lt;CustomMessageOptions&amp;gt;
{
    &lt;span class="rem"&gt;//SiteHelper gets injected via IoC&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; CustomMessageOptionsSetup(SiteHelper siteHelper) 
    : &lt;span class="kwrd"&gt;base&lt;/span&gt;(ConfigureMessageOptions)
    {
        SiteHelper = siteHelper;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; SiteHelper SiteHelper { get; &lt;span class="kwrd"&gt;private&lt;/span&gt; set; }

    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// Set the default options&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ConfigureMessageOptions(CustomMessageOptions options)
    {
        options.Message = &lt;span class="str"&gt;"Hello world"&lt;/span&gt;;
    }

    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// Allows for configuring the options instance before options are set&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Configure(Bundles options, &lt;span class="kwrd"&gt;string&lt;/span&gt; name = &lt;span class="str"&gt;""&lt;/span&gt;)
    {
        &lt;span class="rem"&gt;//Assign the site helper instance&lt;/span&gt;
        options.SiteHelper = SiteHelper;

        &lt;span class="kwrd"&gt;base&lt;/span&gt;.Configure(options, name);
    }
}&lt;/pre&gt;
&lt;p&gt;IRL to give you an example of why this might be useful, in my &lt;a href="https://github.com/Shazwazza/smidge" target="_blank"&gt;Smidge&lt;/a&gt; project I allow developers to create named JavaScript/CSS bundles during startup using options. In some cases a developer might want to manipulate the file processing pipeline for a given bundle and in that case they need access to a service called PreProcessPipelineFactory which needs to come from IoC. The usage might look like:&lt;/p&gt;&lt;pre class="csharpcode"&gt;services.AddSmidge()
    .Configure&amp;lt;Bundles&amp;gt;(bundles =&amp;gt;
    {                   
        bundles.Create(&lt;span class="str"&gt;"test-bundle-3"&lt;/span&gt;, 
            bundles.PipelineFactory.GetPipeline(
                &lt;span class="rem"&gt;//add as many processor types as you want&lt;/span&gt;
                &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(DotLess), &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(JsMin)), 
            WebFileType.Js, 
            &lt;span class="str"&gt;"~/Js/Bundle2"&lt;/span&gt;);
    });&lt;/pre&gt;
&lt;p&gt;In the above, the bundles.PipelineFactory is a property on the bundles (options) class which gets initialized in my own &lt;em&gt;ConfigureOptions&lt;/em&gt; class.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Hopefully this helps anyone looking to use custom options in their AspNet5 libraries!&lt;/p&gt;</description>
      <pubDate>Thu, 23 Mar 2023 15:08:15 Z</pubDate>
      <a10:updated>2023-03-23T15:08:15Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1269</guid>
      <link>https://shazwazza.com/post/introducing-smidge-an-aspnet-5-runtime-jscss-pre-processor/</link>
      <category>ASP.Net</category>
      <category>Web Development</category>
      <title>Introducing ‘Smidge’ – an ASP.NET 5 runtime JS/CSS pre-processor</title>
      <description>&lt;p&gt;During the past month I decided to dive deep into learning ASP.NET 5, and what better way to learn than to start a new OSS project :)&lt;/p&gt;
&lt;p&gt;I chose to make a new new simple and extensible Javascript/CSS &lt;span style="text-decoration: underline;"&gt;runtime&lt;/span&gt; pre-processor for ASP.NET 5. It does file minification, combination and compression, has a nice file caching layer and it’s all done in async operations. I ported over a few ideas and code snippets from &lt;a href="https://github.com/Shazwazza/ClientDependency/" target="_blank"&gt;CDF (client dependency framework)&lt;/a&gt; but with a more modern approach. I’ve called it ‘Smidge’ = &lt;em&gt;something really small&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/Shazwazza/Smidge" target="_blank"&gt;The project is on GitHub&lt;/a&gt;, it’s still a work in progress but its functional and there’s even some documentation! In the next few weeks I’ll get more of the code and docs updated and hopefully have a beta release out. In the meantime, you can clone the source, browse the code, build it and of course use it if you like.&lt;/p&gt;
&lt;h2&gt;Project details&lt;/h2&gt;
&lt;p&gt;It’s currently only targeting &lt;em&gt;aspnet50 &lt;/em&gt;and not the Core CLR… I didn’t start with Core CLR because there was some legacy code I had to port over and I wanted to get something up and working relatively quickly. It shouldn’t be too much work to convert to Core CLR and Mono, hopefully I’ll find time to do that soon. It’s referencing all of the beta-* libraries from the ASP.NET 5 nightly myget feeds since there’s some code I’m using that isn’t available in the current beta1 release (&lt;em&gt;like Microsoft.AspNet.WebUtilities.UriHelper&lt;/em&gt;). The target KRE version is currently &lt;em&gt;KRE-CLR-amd64 1.0.0-beta2-10760.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;Installation&lt;/h2&gt;
&lt;p&gt;I’ve put up an Alpha 1 release on Nuget, so you can install it from there:&lt;/p&gt;
&lt;div class="nuget-badge"&gt;
&lt;p&gt;PM&amp;gt; Install-Package Smidge -Pre&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;There’s some &lt;a href="https://github.com/Shazwazza/Smidge/blob/master/README.md#install" target="_blank"&gt;installation instructions here&lt;/a&gt;, you’ll need to add the smidge.json file yourself for now, can’t figure out how to get VS 2015 (kpm pack) to package that up … more learning required!&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;There’s certainly a lot of detective work involved in learning ASP.NET 5 but with the code being open source and browse-able/searchable on GitHub, it makes finding what you need fairly easy.&lt;/p&gt;</description>
      <pubDate>Thu, 23 Mar 2023 15:08:15 Z</pubDate>
      <a10:updated>2023-03-23T15:08:15Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1277</guid>
      <link>https://shazwazza.com/post/aspnet-5-linux-support-for-runtime-js-css-preprocessing-with-smidge/</link>
      <title>ASP.Net 5 Linux support for runtime JS &amp; CSS preprocessing with Smidge</title>
      <description>&lt;p&gt;I’ve been working on a side project called &lt;a href="https://github.com/Shazwazza/Smidge" target="_blank"&gt;Smidge&lt;/a&gt; which is a runtime JS &amp;amp; CSS preprocessor for ASP.Net 5. I started this late last year after the 2014 MS MVP Summit as a good starting point to deep dive into ASP.Net 5. I’ve been keeping the codebase up-to-date with the beta releases of ASP.Net 5, I have it cross compiled to both dnx451 and dnxcore50 and recently updated to use Beta 7. This week I decided to give running ASP.Net 5 CoreCLR on Linux… and the result is IT WORKS!&lt;/p&gt; &lt;p&gt;I have next to no experience with Linux and considering that, it wasn’t actually very difficult to get my test site for Smidge up and running. Here’s the info on how I set this up:&lt;/p&gt; &lt;h2&gt;Linux setup&lt;/h2&gt; &lt;p&gt;I decided to use Ubuntu 14.04.3 LTS. I installed in on Hyper-V on Windows 10 and that was all very easy. I also setup SSH with the server so that I could remote terminal to it which is much nicer than using the terminal through the UI interface of Ubuntu via Hyper-V. Then basically followed the instructions here: &lt;a title="https://github.com/aspnet/Home/blob/dev/GettingStartedDeb.md#getting-started-with-aspnet-5-and-linux" href="https://github.com/aspnet/Home/blob/dev/GettingStartedDeb.md#getting-started-with-aspnet-5-and-linux.issues"&gt;https://github.com/aspnet/Home/blob/dev/GettingStartedDeb.md#getting-started-with-aspnet-5-and-linux&lt;/a&gt; – except that I didn’t configure any Nuget package sources since that is built into dnvm now. Once that was done I used dnvm to install the default runtime:&amp;nbsp; &lt;strong&gt;dnvm upgrade. &lt;/strong&gt;This installed mono by default but for my purposes I needed ASP.Net 5 CoreCLR since that’s what Smidge is built against and I wanted to see this CoreCLR cross-platform stuff in action. Issuing this command does the trick: &lt;strong&gt;dnvm install 1.0.0-beta7 -r coreclr&lt;/strong&gt; . Now when I list the runtimes installed (&lt;strong&gt;dnvm list&lt;/strong&gt;) I get: &lt;/p&gt; &lt;p&gt;&lt;a href="http://shazwazza.com/media/articulate/windows-live-writer-e42f7a425c51_13ed8-image_2.png"&gt;&lt;img title="image" style="display: inline" alt="image" src="http://shazwazza.com/media/articulate/windows-live-writer-e42f7a425c51_13ed8-image_thumb.png" width="800" height="223"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;So now dnx is installed! We’re ready to go.&lt;/p&gt; &lt;h2&gt;dnu publish &amp;amp; bash&lt;/h2&gt; &lt;p&gt;What I really wanted to see was that I could build my solution on my Windows machine in Visual Studio and then export it and see if it would work on the Linux machine. Through the command line on Windows at the root of my project I used dnu publish (&lt;a title="https://github.com/aspnet/Home/wiki/DNX-utility#publish-dnu-publish" href="https://github.com/aspnet/Home/wiki/DNX-utility#publish-dnu-publish"&gt;https://github.com/aspnet/Home/wiki/DNX-utility#publish-dnu-publish&lt;/a&gt;) which outputs a ‘self-contained directory that can be launched’ = great! So I executed that command, it put the folder in my /bin folder for my current project and I copied over that directory to my Linux machine….&amp;nbsp; and realized I didn’t know what to do next ;)&lt;/p&gt; &lt;p&gt;I had a look through the files that dnu publish exports and the one that is listed in ASP.Net’s docs is the &lt;strong&gt;output/kestrel.cmd &lt;/strong&gt;(since the command in my project is named ‘kestrel’). Inside this file this is listed:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="str"&gt;@"dnx.exe"&lt;/span&gt; --appbase &lt;span class="str"&gt;"%~dp0approot\src\Smidge.Web"&lt;/span&gt; Microsoft.Dnx.ApplicationHost --configuration Debug kestrel %*&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;which if you want to translate to Linux, you could execute this at the Linux terminal at the root of this folder:&lt;/p&gt;&lt;pre class="csharpcode"&gt;dnx --appbase &lt;span class="str"&gt;"approot/src/Smidge.Web"&lt;/span&gt; Microsoft.Dnx.ApplicationHost --configuration Debug kestrel&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;… which will actually work, BUT it turns out there’s a way more &lt;em&gt;Linuxy &lt;/em&gt;way to do it. dnu publish also creates this file which isn’t in the docs:&amp;nbsp; &lt;strong&gt;output/kestrel &lt;/strong&gt;Having a look at this file, the first line is: &lt;strong&gt;#!/usr/bin/env bash &lt;/strong&gt;…&amp;nbsp; so I can only assume this is something for Linux since I’ve heard the term bash before. Turns out on Linux you can just do this in the terminal from the root of this folder!&lt;/p&gt;&lt;pre class="csharpcode"&gt;bash kestrel&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Result:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://shazwazza.com/media/articulate/windows-live-writer-e42f7a425c51_13ed8-image_4.png"&gt;&lt;img title="image" style="display: inline" alt="image" src="http://shazwazza.com/media/articulate/windows-live-writer-e42f7a425c51_13ed8-image_thumb_1.png" width="800" height="83"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;WHOOHOOO!&lt;/p&gt;
&lt;h2&gt;Lets see it in action&lt;/h2&gt;
&lt;p&gt;Now that it’s running, I’ll jump over to the UI in Ubuntu and fire up the browser… Tada!!&lt;/p&gt;
&lt;p&gt;&lt;a href="http://shazwazza.com/media/articulate/windows-live-writer-e42f7a425c51_13ed8-image_6.png"&gt;&lt;img title="image" style="display: inline" alt="image" src="http://shazwazza.com/media/articulate/windows-live-writer-e42f7a425c51_13ed8-image_thumb_2.png" width="600" height="889"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Problems along the way&lt;/h2&gt;
&lt;p&gt;I probably made the above sound a bit easier than it was ;) … I did run into a few setup issues along the way. &lt;/p&gt;
&lt;h4&gt;Problem #1&lt;/h4&gt;
&lt;p&gt;The first one was when I first tried to run dnx:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;failed to locate libcoreclr with error libunwind.so.8: cannot open shared object file: No such file or directory” when you run dnx or dnu command&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I solved this issue from reading about it on this nice post: &lt;a title="http://blogs.msdn.com/b/rdcdev/archive/2015/08/28/some-issues-when-hosting-asp-net-5-on-ubuntu-on-azure.aspx" href="http://blogs.msdn.com/b/rdcdev/archive/2015/08/28/some-issues-when-hosting-asp-net-5-on-ubuntu-on-azure.aspx"&gt;http://blogs.msdn.com/b/rdcdev/archive/2015/08/28/some-issues-when-hosting-asp-net-5-on-ubuntu-on-azure.aspx&lt;/a&gt; which has some other nice tricks if you run into Ubuntu issues with ASP.Net 5.&amp;nbsp; The solution was that I needed to run this command:&lt;/p&gt;&lt;pre class="csharpcode"&gt;sudo apt-get install libunwind8&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;h4&gt;Problem #2&lt;/h4&gt;
&lt;p&gt;Then I got this exception:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The type initializer for 'libcrypto' threw an exception&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Which is referenced on this ASP.Net issue: &lt;a title="https://github.com/aspnet/dnx/issues/1806" href="https://github.com/aspnet/dnx/issues/1806"&gt;https://github.com/aspnet/dnx/issues/1806&lt;/a&gt; … and turns out that it’s also referenced on the above link. I can’t remember where exactly I found this solution but I had to run:&lt;/p&gt;&lt;pre class="csharpcode"&gt;apt-get install libcurl4-openssl-dev&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h4&gt;Problem #3&lt;/h4&gt;
&lt;p&gt;After fixing those 2 things, the bash kestrel command succeeded but when I went to test this in my browser, I just had a white screen. After Googling, I found this link: &lt;a title="http://stackoverflow.com/questions/28845892/blank-white-screen-on-error-with-kestrel-asp-net-5" href="http://stackoverflow.com/questions/28845892/blank-white-screen-on-error-with-kestrel-asp-net-5"&gt;http://stackoverflow.com/questions/28845892/blank-white-screen-on-error-with-kestrel-asp-net-5&lt;/a&gt; and as it turns out, I had the same issue. I forgot to add the error handling middleware. Perhaps when running in VS with IIS this is automatically taken care of for you… not sure. But in any case, it’s super important that you add it and you should add it as the first middleware so you can actually see if your other middleware fails, typically your ‘Configure’ method in your Startup class should start with:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    &lt;span class="rem"&gt;// Add the following to the request pipeline only in development environment.&lt;/span&gt;
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (env.IsDevelopment())
    {
        app.UseErrorPage();
    }
    &lt;span class="kwrd"&gt;else&lt;/span&gt;
    {
        &lt;span class="rem"&gt;// Add Error handling middleware which catches all application specific errors and&lt;/span&gt;
        &lt;span class="rem"&gt;// sends the request to the following path or controller action.&lt;/span&gt;
        app.UseErrorHandler(&lt;span class="str"&gt;"/Home/Error"&lt;/span&gt;);
    }
&lt;/pre&gt;
&lt;h4&gt;Problem #4&lt;/h4&gt;
&lt;p&gt;We’re not in Windows-land anymore! The errors I was getting were due to invalid file system paths. Turns out that .Net has always had this property: &lt;strong&gt;System.IO.Path.DirectorySeparatorChar &lt;/strong&gt;but there wasn’t much reason to use it since .Net only runs in Windows and that character is always backslash. So I had to change my hard coded backslash use to use this instead. Next file path issue was case sensitivity… DOH. The Smidge configuration file is: ~/smidge.json however in my c# code I was trying to load it in with “Smidge.json” which fails in Linux of course. &lt;/p&gt;
&lt;h4&gt;Problem #5&lt;/h4&gt;
&lt;p&gt;Static files… I’m so used to working with IIS I forgot that outside of IIS I’d need to make sure the static file middleware was used:&lt;/p&gt;&lt;pre class="csharpcode"&gt;app.UseStaticFiles();&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;I fixed that up and everything just worked… very freakin cool!!&lt;/p&gt;
&lt;h2&gt;Release – beta6&lt;/h2&gt;
&lt;p&gt;I’ve put up a new release on Nuget with these changes:&lt;/p&gt;
&lt;style type="text/css"&gt;
.nuget-badge code {
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    background-color: #202020;
    border: 4px solid silver;
    border-radius: 5px;
    box-shadow: 2px 2px 3px #6e6e6e;
    color: #e2e2e2;
    display: block;
    font: 1.5em 'andale mono','lucida console',monospace;
    line-height: 1.5em;
    overflow: auto;
    padding: 15px;
}
&lt;/style&gt;

&lt;div class="nuget-badge"&gt;
&lt;p&gt;&lt;code&gt;PM&amp;gt; Install-Package Smidge -Pre &lt;/code&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;And the source is on GitHub: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;beta6 release: &lt;a title="https://github.com/Shazwazza/Smidge/releases/tag/1.0.0-beta5" href="https://github.com/Shazwazza/Smidge/releases/tag/1.0.0-beta6"&gt;https://github.com/Shazwazza/Smidge/releases/tag/1.0.0-beta6&lt;/a&gt; 
&lt;li&gt;home &amp;amp; docs: &lt;a title="https://github.com/Shazwazza/Smidge" href="https://github.com/Shazwazza/Smidge"&gt;https://github.com/Shazwazza/Smidge&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;</description>
      <pubDate>Thu, 23 Mar 2023 15:08:15 Z</pubDate>
      <a10:updated>2023-03-23T15:08:15Z</a10:updated>
    </item>
  </channel>
</rss>