<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rasmus Schultz</title>
    <description>The latest articles on DEV Community by Rasmus Schultz (@mindplay).</description>
    <link>https://dev.to/mindplay</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F51015%2F5b041d2b-1128-43a8-8754-eaa989636cad.jpeg</url>
      <title>DEV Community: Rasmus Schultz</title>
      <link>https://dev.to/mindplay</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mindplay"/>
    <language>en</language>
    <item>
      <title>The Recursive Manifesto</title>
      <dc:creator>Rasmus Schultz</dc:creator>
      <pubDate>Wed, 02 Oct 2024 15:18:15 +0000</pubDate>
      <link>https://dev.to/mindplay/the-recursive-manifesto-48n</link>
      <guid>https://dev.to/mindplay/the-recursive-manifesto-48n</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Why You Should Always Use Recursion&lt;/strong&gt;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Why read this manifesto?
&lt;/h2&gt;

&lt;p&gt;To understand why you should always use recursion, you must first understand why you should always use recursion.&lt;/p&gt;

&lt;h2&gt;
  
  
  Case 1: The Self-Referential Nature of Understanding
&lt;/h2&gt;

&lt;p&gt;To comprehend why recursion is superior, consider the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To understand complex ideas, we break them into simpler parts&lt;/li&gt;
&lt;li&gt;To understand those simpler parts, we must understand recursion&lt;/li&gt;
&lt;li&gt;To understand recursion, read this manifesto&lt;/li&gt;
&lt;li&gt;GOTO 1&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Case 2: The Proof
&lt;/h2&gt;

&lt;p&gt;Let P(n) be the proposition "Recursion is the best solution for problems of size n"&lt;/p&gt;

&lt;p&gt;To prove P(n) for all n ≥ 1:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Base case: For n = 1, recursion is the best solution because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To prove recursion is best for n = 1&lt;/li&gt;
&lt;li&gt;We must use recursion to prove it&lt;/li&gt;
&lt;li&gt;Therefore, recursion is best for n = 1&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Inductive step: Assume P(k) is true for some k ≥ 1&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To prove P(k + 1), we must:&lt;/li&gt;
&lt;li&gt;Break down the problem of size k + 1&lt;/li&gt;
&lt;li&gt;Into a problem of size k (which we know is best solved with recursion)&lt;/li&gt;
&lt;li&gt;Plus a problem of size 1 (which we proved is best solved with recursion)&lt;/li&gt;
&lt;li&gt;Therefore, P(k + 1) must also be true&lt;/li&gt;
&lt;li&gt;Q.E.D.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Case 3: Real-World Applications
&lt;/h2&gt;

&lt;p&gt;Consider how to convince someone to use recursion:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Show them this manifesto&lt;/li&gt;
&lt;li&gt;When they ask why they should believe this manifesto, show them this manifesto&lt;/li&gt;
&lt;li&gt;Repeat until stack overflow or enlightenment, whichever comes first&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Case 4: Counterarguments
&lt;/h2&gt;

&lt;p&gt;For any argument against recursion:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If the argument is simple, solve it recursively&lt;/li&gt;
&lt;li&gt;If the argument is complex, break it into smaller arguments&lt;/li&gt;
&lt;li&gt;GOTO 1&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;You should always use recursion, because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To understand why, refer to the introduction&lt;/li&gt;
&lt;li&gt;To understand the introduction, read this conclusion&lt;/li&gt;
&lt;li&gt;To understand this conclusion, you must understand why you should always use recursion&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Disclaimer
&lt;/h2&gt;

&lt;p&gt;This manifesto may cause infinite recursion in the readers mind. In case of mental stack overflow, remember: the base case is that recursion is awesome.&lt;/p&gt;

</description>
      <category>recursion</category>
    </item>
    <item>
      <title>Easy advanced TypeScript types from day 1</title>
      <dc:creator>Rasmus Schultz</dc:creator>
      <pubDate>Thu, 15 Sep 2022 08:28:59 +0000</pubDate>
      <link>https://dev.to/mindplay/easy-advanced-typescript-types-from-day-1-ohm</link>
      <guid>https://dev.to/mindplay/easy-advanced-typescript-types-from-day-1-ohm</guid>
      <description>&lt;p&gt;Someone proposed a TypeScript feature that could bridge the gap between the JS and TS worlds:&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1570325123948859392-119" src="https://platform.twitter.com/embed/Tweet.html?id=1570325123948859392"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1570325123948859392-119');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1570325123948859392&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"Typing is hard".&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Yes, it is.&lt;/p&gt;

&lt;p&gt;Imagine if this was easy and accessible to everyone from day 1? I really think we need to push for the development of this idea. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advanced types should be for Everyone, not just TypeScript Gurus and people with functional programming experience.&lt;/strong&gt; 🙂✌&lt;/p&gt;

&lt;p&gt;Please 💗 this post, ⭐ and &lt;code&gt;+1&lt;/code&gt; the &lt;a href="https://github.com/microsoft/TypeScript/issues/41577"&gt;issue&lt;/a&gt; - let's get this idea out there!&lt;/p&gt;

&lt;p&gt;Thank You! 🙏&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Zero configuration: what does it mean?</title>
      <dc:creator>Rasmus Schultz</dc:creator>
      <pubDate>Sun, 03 Apr 2022 09:48:05 +0000</pubDate>
      <link>https://dev.to/mindplay/zero-configuration-what-does-it-mean-92c</link>
      <guid>https://dev.to/mindplay/zero-configuration-what-does-it-mean-92c</guid>
      <description>&lt;p&gt;There's a poll attached to this tweet:&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1510515106999898115-638" src="https://platform.twitter.com/embed/Tweet.html?id=1510515106999898115"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1510515106999898115-638');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1510515106999898115&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;Please vote or comment, and share for reach. Thanks! 🙂&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A Custom date-picker in Svelte</title>
      <dc:creator>Rasmus Schultz</dc:creator>
      <pubDate>Thu, 03 Mar 2022 16:21:39 +0000</pubDate>
      <link>https://dev.to/mindplay/a-custom-date-picker-in-svelte-594o</link>
      <guid>https://dev.to/mindplay/a-custom-date-picker-in-svelte-594o</guid>
      <description>&lt;p&gt;I have this fairly small, but fully functional, custom date-picker UI control, which I've been porting between UI frameworks for quite a few years.&lt;/p&gt;

&lt;p&gt;I ported this example to Svelte about 3 years ago, and today I decided to update it to Svelte 3.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://svelte.dev/repl/f391b3186f804fb0bb0931e73388553a?version=3.46.4"&gt;Try it out 🚀&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;br&gt;I always try this first with any new framework to see how they stack up. Perhaps the most important thing demonstrated by this use case, is the ability to validate and conditionally accept a value into the control's internal date state - and the ability to modify the control's view state by navigating through months without changing the value.&lt;/p&gt;

&lt;p&gt;(it was quite a departure from &lt;a href="https://gist.github.com/mindplay-dk/d85fbf5427d5e4436fadc70ce46d9ac2/545c62a647e23a5ffcc5147d8e6af0696169fcf8"&gt;the old version&lt;/a&gt;, in case you'd like to compare.)&lt;/p&gt;

&lt;p&gt;There's not a lot more to say about this. Enjoy. 🙂&lt;/p&gt;

</description>
      <category>svelte</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Typescript module, multiple exports, where do you begin?</title>
      <dc:creator>Rasmus Schultz</dc:creator>
      <pubDate>Thu, 03 Mar 2022 16:14:22 +0000</pubDate>
      <link>https://dev.to/mindplay/typescript-module-multiple-exports-where-do-you-begin-1on9</link>
      <guid>https://dev.to/mindplay/typescript-module-multiple-exports-where-do-you-begin-1on9</guid>
      <description>&lt;p&gt;I'm building a Typescript library. 🤔&lt;/p&gt;

&lt;p&gt;It's going contain several related packages - I want them under a single source-control, but I want them published as packages you can install individually, because some of the packages will have larger dependencies, and I want to keep the main package lightweight.&lt;/p&gt;

&lt;p&gt;I'm guessing I need some sort of monorepo setup? I'd prefer to use whatever is available in plain old &lt;code&gt;npm&lt;/code&gt; - please, no &lt;code&gt;yarn&lt;/code&gt; or third-party monorepo tools.&lt;/p&gt;

&lt;p&gt;At least one of the packages is going to have multiple &lt;code&gt;exports&lt;/code&gt; in &lt;code&gt;package.json&lt;/code&gt; - that is, it will contain multiple modules in the same package. This will make sense for packages that ship with optional modules - keeping them close at hand, but loading them is optional.&lt;/p&gt;

&lt;p&gt;The Typescript source module structure won't necessarily match the published modules - that is, I might decide to use more TS modules published as fewer compiled ES modules, just for cleaner structure, so I will probably need some sort of bundler as well.&lt;/p&gt;

&lt;p&gt;I've looked at &lt;a href="https://www.typescriptlang.org/docs/handbook/project-references.html"&gt;Typescript project references&lt;/a&gt; and &lt;a href="https://docs.npmjs.com/cli/v7/configuring-npm/package-json#workspaces"&gt;npm workspaces&lt;/a&gt;, and it's not clear to me if I need either or both of those?&lt;/p&gt;

&lt;p&gt;I'd like to use &lt;code&gt;esbuild&lt;/code&gt; or &lt;code&gt;rollup&lt;/code&gt; for bundling - but I need &lt;code&gt;exports&lt;/code&gt; in &lt;code&gt;package.json&lt;/code&gt;, which does not seem to be an &lt;code&gt;npm&lt;/code&gt; standard feature? Is it a &lt;code&gt;node&lt;/code&gt; feature? Or is it specific to &lt;a href="https://webpack.js.org/guides/package-exports/"&gt;webpack&lt;/a&gt; maybe? I don't understand where this feature "belongs" or comes from?&lt;/p&gt;

&lt;p&gt;My library should work both on the web and under &lt;code&gt;node&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Emitting &lt;code&gt;.d.ts&lt;/code&gt; files is important, since it's a TS package.&lt;/p&gt;

&lt;p&gt;Publishing modern ES modules would be fine - if this requires a recent version of a browser or &lt;code&gt;node&lt;/code&gt;, that's fine; supporting older platforms is not a concern for this library.&lt;/p&gt;

&lt;p&gt;Supporting Deno is "nice to have" but not a must. I realize I'm already throwing up a &lt;em&gt;long&lt;/em&gt; list of requirements here. It's not completely clear to me if publishing for Deno requires you check-in the compiled files - or if it's better to just structure the TS module sources to fit? If so, I'm willing to do that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where the heck do I start?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'm willing to make concessions here, in favor of simplicity. If that means I have to restructure my code, or if publishing individual packages rather than multi-module packages (with &lt;code&gt;exports&lt;/code&gt;) makes things easier, then yes.&lt;/p&gt;

&lt;p&gt;There's a wealth of articles and documentation, but it's never clear to me which of them apply to my situation. There are so many options and avenues, and every time I sit down to try to figure this out, I get lost and overwhelmed - by the time I have 50 tabs open, I just close everything and give up. 😅&lt;/p&gt;

&lt;p&gt;I really just want to keep things as simple as possible - as few tools and as little configuration as necessary.&lt;/p&gt;

&lt;p&gt;Help? 😄🙏&lt;/p&gt;

</description>
      <category>help</category>
      <category>typescript</category>
      <category>npm</category>
      <category>monorepo</category>
    </item>
    <item>
      <title>It's impossible to get a voice in here</title>
      <dc:creator>Rasmus Schultz</dc:creator>
      <pubDate>Tue, 22 Feb 2022 09:53:07 +0000</pubDate>
      <link>https://dev.to/mindplay/its-impossible-to-get-a-voice-in-here-4aop</link>
      <guid>https://dev.to/mindplay/its-impossible-to-get-a-voice-in-here-4aop</guid>
      <description>&lt;p&gt;Twice now, I've spent considerable time carefully writing an article, just to watch it get 20-30 hits in the first hour, and then disappear into oblivion - never to be seen by anyone again.&lt;/p&gt;

&lt;p&gt;If my content was bad, I could understand it - but I've been told (by Dev staff and other developers) that it's really helpful. I don't like to be the judge of my own work, but I don't think my content is bad.&lt;/p&gt;

&lt;p&gt;It's great to see the site become a success - but the sheer volume of traffic in here apparently makes it impossible to get a voice.&lt;/p&gt;

&lt;p&gt;Putting work into an article feels like a complete waste of time.&lt;/p&gt;

&lt;p&gt;I'm not famous or well known (and don't wish to be) so I don't have a million Twitter followers or some other way to get people to notice my content.&lt;/p&gt;

&lt;p&gt;I'm guessing that's the only way your content gets noticed here?&lt;/p&gt;

&lt;p&gt;It's on the front page for an hour, tops, and then it's gone.&lt;/p&gt;

&lt;p&gt;It looks like a quick paragraph or 5-10 words like "do you like X?" or "how do you feel about Y?" gets the same amount of air time on Dev as anything else - and maybe the site equally weighs discussions and actual content?&lt;/p&gt;

&lt;p&gt;Mixing discussions and articles into a single stream might not be working well?&lt;/p&gt;

&lt;p&gt;I don't know how to fix this, but I've brought it up with the Dev staff before, and they seemed to agree, this is not really working well.&lt;/p&gt;

&lt;p&gt;This makes me wonder as well, how much good content from other contributors am I missing? How much actual content gets drowned out by quick prompts and baits?&lt;/p&gt;

&lt;p&gt;Honestly, I probably won't bother writing anything else here again until or unless you manage to do something smart about this.&lt;/p&gt;

&lt;p&gt;There has got to be some way you can give air time to actual content?&lt;/p&gt;

&lt;p&gt;Very frustrating.&lt;/p&gt;

&lt;p&gt;I feel like Dev has far more potential than what it's delivering right now.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;/rant&amp;gt;&lt;/code&gt;&lt;/p&gt;

</description>
      <category>meta</category>
    </item>
    <item>
      <title>Containerless Dependency Injection in C#</title>
      <dc:creator>Rasmus Schultz</dc:creator>
      <pubDate>Mon, 21 Feb 2022 18:22:40 +0000</pubDate>
      <link>https://dev.to/mindplay/containerless-dependency-injection-in-c-1nid</link>
      <guid>https://dev.to/mindplay/containerless-dependency-injection-in-c-1nid</guid>
      <description>&lt;h3&gt;
  
  
  🧡 Dependency injection is at the heart of every good piece of software.
&lt;/h3&gt;

&lt;p&gt;In most typical projects, dependency injection is implemented by configuring some sort of dependency injection (DI) container.&lt;/p&gt;

&lt;p&gt;If you don't have a DI container available, if you don't understand how your DI container works, or if you just don't like the idea of having a complex facility for something that is ultimately pretty simple, in this article, I will demonstrate a really simple DI pattern that does not require any container library or framework.&lt;/p&gt;

&lt;p&gt;In this example, we'll be bootstrapping a few simple mock components - to keep the discussion focused, these don't have any actual implementations, just constructor arguments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Connection&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;connectionString&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserService&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;UserService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Connection&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;WebRequest&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;WebRequest&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ListUsersController&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;ListUsersController&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;UserService&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;WebRequest&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So we have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a &lt;code&gt;Connection&lt;/code&gt; representing a database connection object,&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;UserService&lt;/code&gt; that requires a &lt;code&gt;Connection&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;WebRequest&lt;/code&gt; representing an incoming HTTP request (which would be generated by an HTTP server component of some sort) and&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;ListUsersController&lt;/code&gt; which depends on the &lt;code&gt;UserService&lt;/code&gt; and an incoming &lt;code&gt;WebRequest&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that the &lt;code&gt;Connection&lt;/code&gt; class in this example has a dependency on a &lt;code&gt;connectionString&lt;/code&gt; - we will use this to illustrate the difference between dependencies on something from the &lt;em&gt;external environment&lt;/em&gt;, versus dependencies within the &lt;em&gt;internal application&lt;/em&gt;: an external dependency such as this has to come from somewhere outside the application, such as a configuration file or environment variable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Contexts
&lt;/h3&gt;

&lt;p&gt;Instances of our components have to be created and held somewhere, for the duration of their lifetime - personally, I like to refer to this "somewhere" as a &lt;strong&gt;context&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We could say, for example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"a controller exists within the context of a web request"&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For our example, we need two contexts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An &lt;code&gt;ApplicationContext&lt;/code&gt; for components that exist for the entire lifetime of the running application, and&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;RequestContext&lt;/code&gt; for components that exist only within the context of a specific web-request.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So you can see why the distinction is important: while the application context is going to exist for as long as your application is running, request contexts are going to come and go with individual web requests, as they are received and routes to different controllers with different dependencies.&lt;/p&gt;

&lt;p&gt;In practice, the implementation of a context is just a class with fields to hold the instances of our components - for each component we need:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A &lt;code&gt;private&lt;/code&gt; field to hold the component instance. To make sure we don't create our components before (or unless) they're needed, we store every component instance in a &lt;a href="https://docs.microsoft.com/en-us/dotnet/api/system.lazy-1?view=net-6.0"&gt;&lt;code&gt;System.Lazy&amp;lt;Y&amp;gt;&lt;/code&gt;&lt;/a&gt; instance.&lt;/li&gt;
&lt;li&gt;An initialization in the constructor. This is where we define the factory functions for each of our components, by injecting an anonymous function (a closure) into the appropriate &lt;code&gt;Lazy&amp;lt;T&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A public accessor. This is how we retrieve component instance from the context.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For the &lt;code&gt;ApplicationContext&lt;/code&gt;, this looks like the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ApplicationContext&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="n"&gt;Lazy&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_connection&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="n"&gt;Lazy&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;UserService&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_userService&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;ApplicationContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;connectionString&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;_connection&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;connectionString&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="n"&gt;_userService&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;UserService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;Connection&lt;/span&gt; &lt;span class="n"&gt;Connection&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;UserService&lt;/span&gt; &lt;span class="n"&gt;UserService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_userService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just to give you a feel for the "rhythm" of this pattern, I included a public accessor for &lt;code&gt;Connection&lt;/code&gt; - if a given component is only used internally within the context, exposing it via an accessor might not be necessary; you should decide what you need or want to expose.&lt;/p&gt;

&lt;p&gt;Let's go ahead and define our &lt;code&gt;RequestContext&lt;/code&gt; as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RequestContext&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="n"&gt;Lazy&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;ListUsersController&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_listUsersController&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;RequestContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ApplicationContext&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;WebRequest&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;_listUsersController&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ListUsersController&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;UserService&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;ListUsersController&lt;/span&gt; &lt;span class="n"&gt;ListUsersController&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_listUsersController&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that a &lt;code&gt;RequestContext&lt;/code&gt; requires an &lt;code&gt;ApplicationContext&lt;/code&gt;. Recall how, in the beginning of the article, we described the &lt;code&gt;connectionString&lt;/code&gt; required for an &lt;code&gt;ApplicationContext&lt;/code&gt; as an "external dependency"?&lt;/p&gt;

&lt;p&gt;In the same sense, the &lt;code&gt;ApplicationContext&lt;/code&gt; is "external" to the &lt;code&gt;RequestContext&lt;/code&gt;: from within the boundary of a &lt;code&gt;RequestContext&lt;/code&gt;, an &lt;code&gt;ApplicationContext&lt;/code&gt; is the external world - an environment with it's own distinct life-cycle.&lt;/p&gt;

&lt;p&gt;As you can see, our model now consists of long-lived, shared components in one context - as well as more short-lived, request-specific components in a different context.&lt;/p&gt;

&lt;p&gt;Finally, let's briefly illustrate how to put these together:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ApplicationContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"user=blah;password=meh"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;WebRequest&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;requestContext&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;RequestContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;controller&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requestContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ListUsersController&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, in an automated test, you might actually write code in a linear fashion like this - and being able to wire up real dependencies for integration testing is certainly a benefit of this pattern.&lt;/p&gt;

&lt;p&gt;In a real project, some kind of long-lived server component (in the application context) would provide a proper &lt;code&gt;WebRequest&lt;/code&gt; for a handler of some sort, which would generate a &lt;code&gt;RequestContext&lt;/code&gt;, apply some pattern matching, pick the right controller, and so on...&lt;/p&gt;

&lt;p&gt;Building an actual application is outside the scope of this article - the point of this example is to illustrate the fact that &lt;strong&gt;components exist in different contexts&lt;/strong&gt; because they have &lt;strong&gt;different life-cycles&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here is a &lt;a href="https://dotnetfiddle.net/N0UClh"&gt;running playground&lt;/a&gt; for you to try out - I encourage you to play around with the dependencies, perhaps mock out an example with mock components from a project you're currently working on, and get a feel for it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusions
&lt;/h3&gt;

&lt;p&gt;The beauty of this pattern, is that it scales beautifully to complex projects - while a dependency graph can get very large, this simple pattern allows you to deal with the creation of each component individually, while the larger graph of dependencies simply unfolds and resolves itself through the use of &lt;code&gt;Lazy&amp;lt;T&amp;gt;&lt;/code&gt; and simple accessors.&lt;/p&gt;

&lt;p&gt;The arguable downside of not using a DI container, is that you do need to manually define the creation of every component - personally, I don't find this pattern too verbose, and I actually like the fact that a breaking change to a constructor &lt;em&gt;requires&lt;/em&gt; me to consider the impact on other components.&lt;/p&gt;

&lt;p&gt;Lastly, someone asked me, what would happen if we accidentally created a circular dependency - would the program go into an infinite loop, terminating with a stack overflow? Well, &lt;a href="https://dotnetfiddle.net/zCGVzE"&gt;see for yourself&lt;/a&gt; - but no, &lt;code&gt;Lazy&amp;lt;T&amp;gt;&lt;/code&gt; actually throws an exception in this situation, which is good news. Arguably, the error message might not be as helpful as it might be with a DI container - but if you make this mistake, at least you won't be setting any servers on fire. 😆🔥&lt;/p&gt;

&lt;p&gt;I hope this article gave you an idea of just how simple dependency injection can actually be. Happy coding! 🙋‍♂️&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>architecture</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Test-driven vs test-first</title>
      <dc:creator>Rasmus Schultz</dc:creator>
      <pubDate>Tue, 13 Jul 2021 10:12:42 +0000</pubDate>
      <link>https://dev.to/mindplay/test-driven-vs-test-first-24ea</link>
      <guid>https://dev.to/mindplay/test-driven-vs-test-first-24ea</guid>
      <description>&lt;p&gt;I've tried test-first many times over my career, and I will happily admit that it &lt;em&gt;does not work for me&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;If it works for you, that's great. But personally, I need to think about the code and the design first, &lt;em&gt;before&lt;/em&gt; I know what I need to test.&lt;/p&gt;

&lt;h3&gt;
  
  
  How I Write Code
&lt;/h3&gt;

&lt;p&gt;My workflow is very much driven by tests.&lt;/p&gt;

&lt;p&gt;I typically write one function, or maybe just part of a function, with testing in mind - and then I add the test. I would agree that test-&lt;em&gt;last&lt;/em&gt; is not a good strategy, but what works best for me, personally, is to &lt;em&gt;alternate&lt;/em&gt; between writing code and tests.&lt;/p&gt;

&lt;p&gt;For one, I find that writing the test first is just too clumsy in type-safe languages. I don't want to have the IDE screaming at me the whole way - if I write the test first, there is no auto-completion, or sometimes the wrong auto-completion.&lt;/p&gt;

&lt;p&gt;But more than that, I simply haven't discovered the right shape or form of the code yet - and that is something I want to tease out, discover and adjust, &lt;em&gt;before&lt;/em&gt; committing to a public interface, which I'm going to be testing against.&lt;/p&gt;

&lt;p&gt;In other words, my code is definitely driven by tests - but it's not &lt;em&gt;exclusively&lt;/em&gt; driven by tests. Plenty of other factors inform the design of my code - for example, the existing code, and the language itself, both inform and constrain a design.&lt;/p&gt;

&lt;p&gt;I design for testability, but perhaps more than that, I design for readability - which isn't something that I, personally, can just intuit, ahead of actually writing code.&lt;/p&gt;

&lt;h3&gt;
  
  
  More Roads to Rome
&lt;/h3&gt;

&lt;p&gt;We both strive for the same values, and arrive at code with the same qualities: it works, it's modular, it's cohesive, it's decoupled, it has good separation of concerns and meaningful abstractions. We both want readable tests that test the right things, aren't too dependent on implementation details, and so on.&lt;/p&gt;

&lt;p&gt;In my experience, the difference between the test-first approach and my approach is largely personality - rather than outcomes.&lt;/p&gt;

&lt;p&gt;My code is just as informed and driven by tests, at every step of the process, as your test-first code. My approach is every bit as test-&lt;em&gt;driven&lt;/em&gt; as yours.&lt;/p&gt;

&lt;p&gt;I just don't have the exact same process and mental model that happens to work for you.&lt;/p&gt;

&lt;p&gt;Since you've been insisting on test-first for much of my career, of course I've tried it, and more than once. And frankly, if I were forced to write my tests first, my code and tests would not be as good as they are.&lt;/p&gt;

&lt;p&gt;It's simply not how my mind works, and I'm definitely not alone in feeling this way either - I know plenty of capable, experienced developers who feel the same way.&lt;/p&gt;

&lt;h3&gt;
  
  
  Finding Balance
&lt;/h3&gt;

&lt;p&gt;I wish you would not conflate test-first with test-driven.&lt;/p&gt;

&lt;p&gt;And please don't give me your song about the original definition or meaning of the word "test-driven" - I understand the origins of these words, but they are &lt;em&gt;just words&lt;/em&gt;. Nobody owns them.&lt;/p&gt;

&lt;p&gt;My approach is neither test-&lt;em&gt;first&lt;/em&gt; or test-&lt;em&gt;after&lt;/em&gt; - I'd like to refer to it as test-&lt;em&gt;along&lt;/em&gt;, and I wish you would acknowledge the fact that it is every bit as test-&lt;em&gt;driven&lt;/em&gt; as your test-first approach.&lt;/p&gt;

&lt;p&gt;If you belong to this group of test-first enforcers, I hope that you would reconsider your position on this. There is an approach between test-first and test-after, which, to me and many others, is just as efficient, practical and meaningful as your test-first approach.&lt;/p&gt;

&lt;p&gt;In fact, I would urge you to try it.&lt;/p&gt;

&lt;p&gt;In my experience, a balanced approach, in software development — &lt;em&gt;as it is everywhere in life&lt;/em&gt; — is usually better than polar extremes.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>testing</category>
      <category>tdd</category>
    </item>
    <item>
      <title>A Successful IOC Pattern with Functions in TypeScript</title>
      <dc:creator>Rasmus Schultz</dc:creator>
      <pubDate>Sun, 20 Jun 2021 19:12:41 +0000</pubDate>
      <link>https://dev.to/mindplay/a-successful-ioc-pattern-with-functions-in-typescript-2nac</link>
      <guid>https://dev.to/mindplay/a-successful-ioc-pattern-with-functions-in-typescript-2nac</guid>
      <description>&lt;p&gt;Over the past few months, I've been working on a TypeScript project, where I decided to challenge myself to use Functions only. This week, I refactored the codebase to use &lt;a href="https://en.wikipedia.org/wiki/Inversion_of_control"&gt;IOC&lt;/a&gt; everywhere, and it feels like I &lt;em&gt;leveled up&lt;/em&gt;. 😄&lt;/p&gt;

&lt;p&gt;There's been a lot of articles these past couple of years about "functional programming" in JavaScript, and for some reason these are mostly concerned with immutability, sets, map/reduce, and so on. I come from a background of mostly OOP, where the answer to IOC is largely just "use constructors and interfaces", so this hasn't been really helpful.&lt;/p&gt;

&lt;p&gt;What was missing for me, was a functional perspective on IOC and dependency injection.&lt;/p&gt;

&lt;p&gt;In this article, I will try to illustrate the problems and solutions with a &lt;em&gt;silly&lt;/em&gt; example for illustration purposes: for some reason, your boss wants the browser to display a personalized welcome message using an old-fashioned alert. Yikes. Well, whatever you say, boss, but I &lt;em&gt;expect&lt;/em&gt; this requirement will change in the future.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;To make the most of this article, you should know some basic TypeScript, and you should be familiar with the terms "inversion of control" or "dependency injection" - at least in the sense of using constructors and interfaces.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;While&lt;/em&gt; &lt;code&gt;DEV&lt;/code&gt; &lt;em&gt;thinks this is "an 8 minute read", I recommend you open the &lt;a href="https://www.typescriptlang.org/play"&gt;Playground&lt;/a&gt; and spend 20-30 minutes getting a feel for this.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Okay, let's say you come up with function like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;showMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Window&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, I am already doing dependency injection. Rather than reaching out for the &lt;code&gt;window&lt;/code&gt; global, this function asks for an instance of &lt;code&gt;Window&lt;/code&gt;, which makes it easy to unit-test this function on a mock &lt;code&gt;Window&lt;/code&gt; instance. So far so good.&lt;/p&gt;

&lt;p&gt;💭 &lt;em&gt;So we're done, right?&lt;/em&gt; 😁&lt;/p&gt;

&lt;p&gt;Not quite.&lt;/p&gt;

&lt;p&gt;Pretty soon, you will introduce functions that depend on &lt;code&gt;showMessage&lt;/code&gt; - and, in order for another function to call &lt;code&gt;showMessage&lt;/code&gt;, the other function needs to supply the &lt;code&gt;window&lt;/code&gt; parameter - which means the dependency on &lt;code&gt;Windows&lt;/code&gt; &lt;em&gt;spreads&lt;/em&gt; to other functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;showWelcomeMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Window&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;showMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`Welcome, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But wait, now &lt;code&gt;showWelcomeMessage&lt;/code&gt; internally depends on &lt;code&gt;showMessage&lt;/code&gt; - we really should use dependency injection for that too, right?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;showMessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;showMessage&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;showWelcomeMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;showMessage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;showMessage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Window&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;showMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`Welcome, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💭 &lt;em&gt;This looks wrong.&lt;/em&gt; 🤨&lt;/p&gt;

&lt;p&gt;&lt;code&gt;showWelcomeMessage&lt;/code&gt; had to depend on &lt;code&gt;Window&lt;/code&gt;, only so it could pass it along to &lt;code&gt;showMessage&lt;/code&gt; - but it doesn't actually &lt;em&gt;do&lt;/em&gt; anything with the &lt;code&gt;Window&lt;/code&gt; object itself.&lt;/p&gt;

&lt;p&gt;And while &lt;code&gt;showMessage&lt;/code&gt; happens to use &lt;code&gt;Window&lt;/code&gt; today, we might change that in the future, when someone realizes what a sad idea it was to use that alert. Maybe we decide to have it display a toast message on the page instead, and so the dependency changes from &lt;code&gt;Window&lt;/code&gt; to &lt;code&gt;Document&lt;/code&gt;. That's a breaking change. Now we have to run around and refactor everything that calls &lt;code&gt;showMessage&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Calling any function gets increasingly cumbersome - anytime any of the dependencies of any function changes, we have to manually correct the calls and introduce more dependencies everywhere. We're in &lt;em&gt;dependency hell&lt;/em&gt;, and by now we're wasting most of our time refactoring.&lt;/p&gt;

&lt;p&gt;💭 &lt;em&gt;There has to be a better way.&lt;/em&gt; 🤔&lt;/p&gt;

&lt;p&gt;My first realization was, why should someone who wants to call &lt;code&gt;showMessage&lt;/code&gt; need to know anything about it's internal dependencies? What I really want, is a function that is &lt;em&gt;internally bound&lt;/em&gt; to an instance of &lt;code&gt;Window&lt;/code&gt;, so that the caller doesn't need to know or care.&lt;/p&gt;

&lt;p&gt;That means we need a &lt;em&gt;factory&lt;/em&gt;-function for the &lt;em&gt;actual&lt;/em&gt; function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createShowMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Window&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;showMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll need to extract the inner function-type - the one that has the &lt;code&gt;message&lt;/code&gt; argument only, so that other units can depend on that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;showMessage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;ReturnType&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;createShowMessage&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Note the user of &lt;a href="https://www.typescriptlang.org/docs/handbook/utility-types.html#returntypetype"&gt;&lt;code&gt;ReturnType&lt;/code&gt;&lt;/a&gt; here - you could have manually typed out the function signature of the inner function, but this helps avoid the duplication and the extra refactoring chore going forward.)&lt;/p&gt;

&lt;p&gt;With that in place, our &lt;code&gt;showWelcomeMessage&lt;/code&gt; no longer needs to care that &lt;code&gt;showMessage&lt;/code&gt; internally uses &lt;code&gt;window&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;showWelcomeMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;showMessage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;showMessage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;showMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Welcome, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This also makes &lt;code&gt;showWelcomeMessage&lt;/code&gt; easier to test, since now we don't need to mock &lt;code&gt;window&lt;/code&gt; anymore - we can mock &lt;code&gt;showMessage&lt;/code&gt; instead and test that it's being called. The code and the tests will now refactor much better, as they have fewer reasons to change.&lt;/p&gt;

&lt;p&gt;💭 &lt;em&gt;So we're done, right?&lt;/em&gt; 😅&lt;/p&gt;

&lt;p&gt;Yeah, but No.&lt;/p&gt;

&lt;p&gt;Consider now what happens to the next function up the call hierarchy. Let's say we have a &lt;code&gt;login&lt;/code&gt; function, and showing the welcome message happens to be part of what it does - and we apply dependency injection here, too:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;showWelcomeMessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;showWelcomeMessage&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;showWelcomeMessage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;showWelcomeMessage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;showWelcomeMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This problem doesn't go away by just fixing it at one level - we need to apply the same pattern we applied to &lt;code&gt;showMessage&lt;/code&gt;, wrapping it in a &lt;code&gt;createShowMessage&lt;/code&gt; factory-function. And what happens when something else needs to call &lt;code&gt;login&lt;/code&gt;? Same thing again.&lt;/p&gt;

&lt;p&gt;In fact, as you may have realized by now, we might as well apply this pattern consistently, as a convention, to every function we write.&lt;/p&gt;

&lt;p&gt;💭 &lt;em&gt;Really? To every function?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Yes, really - and bear with me, because it doesn't &lt;em&gt;look&lt;/em&gt; pretty:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createShowMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Window&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;showMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;showMessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;ReturnType&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;createShowMessage&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createShowWelcomeMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;showMessage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;showMessage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;showWelcomeMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;showMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Welcome, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;showWelcomeMessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;ReturnType&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;createShowWelcomeMessage&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createLogin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;showWelcomeMessage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;showWelcomeMessage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;showWelcomeMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;createLogin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;ReturnType&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;createLogin&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It does what we wanted though. We can do all of our dependency injection from the top down now - we can now bootstrap everything from a single function in our entry-point script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;bootstrap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Window&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;showMessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createShowMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;showWelcomeMessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createShowWelcomeMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;showMessage&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;login&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createLogin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;showWelcomeMessage&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;login&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// usage:&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;login&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;bootstrap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Rasmus&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that, in this example, &lt;code&gt;bootstrap&lt;/code&gt; returns only &lt;code&gt;login&lt;/code&gt; - if you have multiple entry-points, you can return more functions.&lt;/p&gt;

&lt;p&gt;Now, as helpful as this pattern was, this approach to bootstrapping does not really scale well. There are two problems:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We're creating everything up front. In this simple example, we do need every component - but applications with multiple entry-points might only need some of the components, some of the time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The code is very sensitive to reordering: you have to carefully arrange your factory-function calls, so that the previous function can be passed to the next. It requires a lot of thinking about dependencies.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We can solve both of these problems by &lt;em&gt;deferring&lt;/em&gt; the creation of dependencies until they're required - that is, by making the calls to the factory-functions from within &lt;em&gt;another&lt;/em&gt; function. Let's call this a &lt;em&gt;getter&lt;/em&gt;-function.&lt;/p&gt;

&lt;p&gt;Now, since these getter-functions could potentially be called more than once (although, in this simple example, they're not) we want them to return the &lt;em&gt;same&lt;/em&gt; dependency every time - rather than generating new ones.&lt;/p&gt;

&lt;p&gt;We can solve this by adding a tiny helper-function &lt;code&gt;once&lt;/code&gt; to construct these wrapper-functions and &lt;a href="https://en.wikipedia.org/wiki/Memoization"&gt;memoize&lt;/a&gt; the result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;once&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;f&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// first call&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; 

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's refactor again: we'll wrap all of our initializations in closures and apply &lt;code&gt;once&lt;/code&gt; to them - and our &lt;code&gt;bootstrap&lt;/code&gt; function will now return the &lt;code&gt;getLogin&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;(Note that the &lt;code&gt;once&lt;/code&gt; function would generate &lt;a href="https://en.wikipedia.org/wiki/Singleton_pattern"&gt;singletons&lt;/a&gt;, if you were to call it from the global scope - but since we're calling it from the &lt;code&gt;bootstrap&lt;/code&gt; function scope, new instances of all dependencies will be generated for every call to &lt;code&gt;bootstrap&lt;/code&gt;.)&lt;/p&gt;

&lt;p&gt;The new bootstrap-function looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;bootstrap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Window&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getLogin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;once&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;createLogin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;getShowWelcomeMessage&lt;/span&gt;&lt;span class="p"&gt;()));&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getShowWelcomeMessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;once&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;createShowWelcomeMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;getShowMessage&lt;/span&gt;&lt;span class="p"&gt;()));&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getShowMessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;once&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;createShowMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;getLogin&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// usage:&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;bootstrap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;login&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getLogin&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Rasmus&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I've purposely mixed-up the order of these getter-functions, to illustrate the fact that the order no longer matters: we're now free to arrange and group these lines in any order that makes sense - and we're also no longer creating anything before one of the getter-functions is actually called, which removes any concerns about potential future performance problems.&lt;/p&gt;

&lt;p&gt;💭 &lt;em&gt;So we're...?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Yes, done! 🏆✨&lt;/p&gt;

&lt;h4&gt;
  
  
  Footnote: When &lt;em&gt;not&lt;/em&gt; to apply this pattern
&lt;/h4&gt;

&lt;p&gt;You don't need to apply this pattern to every function. Some functions don't have dependencies, or maybe they depend only on standard JavaScript environment functions.&lt;/p&gt;

&lt;p&gt;For example, there's no benefit to injecting the &lt;code&gt;Math.max&lt;/code&gt; function, since that's a &lt;a href="https://en.wikipedia.org/wiki/Pure_function"&gt;pure function&lt;/a&gt; with no side-effects. Whereas, on the other hand, there's a clear benefit to injecting &lt;code&gt;Math.random&lt;/code&gt;, since a mock can return values that aren't actually random - making it possible to write predictable tests for your function.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bonus: Mutable State
&lt;/h3&gt;

&lt;p&gt;I made one more little discovery this week that I'd like to share.&lt;/p&gt;

&lt;p&gt;I think we've all been &lt;em&gt;here&lt;/em&gt; one time or another?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;loggedInUser&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;setLoggedInUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;loggedInUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getLoggedInUser&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;loggedInUser&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's dangerously easy and natural to do this in JavaScript. 💣&lt;/p&gt;

&lt;p&gt;But even if you put this inside a module, this is &lt;em&gt;global state&lt;/em&gt; - and it makes things difficult to test, since &lt;code&gt;setLoggedInUser&lt;/code&gt; leaves behind in-memory state that persists between tests. (And you could write more code to clear out this state between tests, but, ugh.)&lt;/p&gt;

&lt;p&gt;If you &lt;em&gt;must&lt;/em&gt; have mutable state, we need to model that mutable &lt;code&gt;loggedInUser&lt;/code&gt; state as a dependency, and then apply the create-function pattern described above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;LoginState&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;loggedInUser&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createSetLoggedInUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;LoginState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;setLoggedInUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loggedInUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createGetLoggedInUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;LoginState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getLoggedInUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loggedInUser&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I could have abbreviated this more, but I actually like seeing the word &lt;code&gt;state&lt;/code&gt; here, clarifying the fact that a shared state is being either read or written.&lt;/p&gt;

&lt;p&gt;It might be tempting to just take the previous version of this code, wrap it all in a single create-function, and return both of the functions, bound to the same &lt;code&gt;state&lt;/code&gt; - but I wouldn't recommend that, because you could end up with &lt;em&gt;many&lt;/em&gt; functions that depend on this state, and you don't want to be forced to declare them &lt;em&gt;all&lt;/em&gt; in the same create-function. (Also, if you have to write a function that depends on &lt;em&gt;several&lt;/em&gt; different state objects, that approach does not work.)&lt;/p&gt;

&lt;p&gt;One more piece of advice: don't just create one big state object for all of your mutable state - this will muddy your dependencies, as functions will appear to depend on "the entire application state", even when those functions only actually depend on one property. (If you have multiple properties in the same state object, the &lt;a href="https://en.wikipedia.org/wiki/Cohesion_(computer_science)"&gt;cohesion&lt;/a&gt; should be high - ideally 100%, meaning every function depends on &lt;em&gt;all&lt;/em&gt; of the properties of that object.)&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;setLoggedInUser&lt;/code&gt; function &lt;em&gt;does&lt;/em&gt; have a &lt;a href="https://en.wikipedia.org/wiki/Side_effect_(computer_science)"&gt;side-effect&lt;/a&gt;, but now the effect is on state that you instantiate and control - making it easy to inject a new state for every test.&lt;/p&gt;

&lt;p&gt;I'm not a functional programming Guru &lt;em&gt;yet&lt;/em&gt;, and maybe there is more to learn here, but it's definitely a step up from global state. 🙂&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;I feel like I've finally found a JS/TS code-style that really scales - both in terms of complexity and performance.&lt;/p&gt;

&lt;p&gt;Applying this to my codebase has been an absolute breeze. I'm spending considerably less time juggling dependencies or refactoring things. Unit-testing is never a problem anymore.&lt;/p&gt;

&lt;p&gt;For years, I've heard proponents of functional programming talk about the benefits - but the articles are mostly about arrays and immutability, which is great, and I've heard all the other great arguments. But it didn't really help me &lt;em&gt;write software&lt;/em&gt;, and the outcome of prior attempts too often was either unmanageable or untestable. (But usually both.)&lt;/p&gt;

&lt;p&gt;Unlocking this feels like the "next level" for me, and I really hope this puts somebody else on the path to more productive and scalable codebases with TypeScript or JavaScript.&lt;/p&gt;

&lt;p&gt;Thanks for reading. Have fun! 😀✌&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>ioc</category>
      <category>functional</category>
    </item>
    <item>
      <title>How to quit the perfect job?</title>
      <dc:creator>Rasmus Schultz</dc:creator>
      <pubDate>Thu, 22 Aug 2019 15:12:39 +0000</pubDate>
      <link>https://dev.to/mindplay/how-to-quit-the-perfect-job-54c1</link>
      <guid>https://dev.to/mindplay/how-to-quit-the-perfect-job-54c1</guid>
      <description>&lt;p&gt;&lt;em&gt;How do you quit the perfect job?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the past 6 years, I've had a key role in the creation of the most beautiful web architecture I've ever worked with.&lt;/p&gt;

&lt;p&gt;It's simple, elegant, efficient, and an absolute joy to work on - and, above all, it's successful: turn-around time is fast, features live up to user expectations, defects are extremely rare and often quickly resolved.&lt;/p&gt;

&lt;p&gt;I've had the joy of successfully teaching the principles, practices, values, patterns and techniques to a team, guiding them on a daily basis to successful, enjoyable, consistent work - the feedback has been almost exclusively positive, and negative feedback has almost always lead to durable improvements.&lt;/p&gt;

&lt;p&gt;It's been deeply rewarding, on both a professional and personal level.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In my 21 years of web development, I've never been more pleased with the work.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;But all good things come to an end.&lt;/p&gt;

&lt;p&gt;I won't go into the reasons, which are personal - but after struggling with this decision, day and night, for weeks on end, I'm resolved: I have to quit and move on.&lt;/p&gt;

&lt;p&gt;My question is, &lt;strong&gt;how do you do that?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I've been scouring the job boards, and it just seems like &lt;em&gt;everything&lt;/em&gt; is going to suck in comparison: overly complex systems built on bloated frameworks, default architecture, code-generators, object/relational-mappers, tools and practices that generally go against everything I stand for and believe in.&lt;/p&gt;

&lt;p&gt;I feel like I've been blessed and cursed all at once. I was lucky enough to arrive at a time when my employer was willing to rebuild from ground up - in my experience, that practically never happens. I don't live in a capital city, so startups are rare - and most startups just want rapid prototypes and quick entry to markets, anyhow.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;How do you move on after an experience like this?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you've been in a similar situation, any experience you can share would be greatly appreciated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thank You!&lt;/strong&gt; ✨&lt;/p&gt;

</description>
      <category>career</category>
      <category>help</category>
      <category>discuss</category>
    </item>
    <item>
      <title>"Bringing Peace to the Galaxy" (Zeev Suraski on PHP internals)</title>
      <dc:creator>Rasmus Schultz</dc:creator>
      <pubDate>Sat, 10 Aug 2019 10:30:46 +0000</pubDate>
      <link>https://dev.to/mindplay/bringing-peace-to-the-galaxy-zeev-suraski-on-php-internals-5hin</link>
      <guid>https://dev.to/mindplay/bringing-peace-to-the-galaxy-zeev-suraski-on-php-internals-5hin</guid>
      <description>&lt;p&gt;Really interesting post on the PHP internals mailing list:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://externals.io/message/106453"&gt;https://externals.io/message/106453&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;The post was followed up by this FAQ:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://wiki.php.net/pplusplus/faq"&gt;https://wiki.php.net/pplusplus/faq&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;This discussion is painfully over due, and I'm just thrilled to see it finally taking place! :-)&lt;/p&gt;

</description>
      <category>php</category>
    </item>
    <item>
      <title>Anything like PHP's PSR-7/15 for C# and ASP.NET Core?</title>
      <dc:creator>Rasmus Schultz</dc:creator>
      <pubDate>Wed, 17 Apr 2019 13:25:04 +0000</pubDate>
      <link>https://dev.to/mindplay/anything-like-php-s-psr-7-15-for-c-and-asp-net-core-5b48</link>
      <guid>https://dev.to/mindplay/anything-like-php-s-psr-7-15-for-c-and-asp-net-core-5b48</guid>
      <description>&lt;p&gt;I've been using PHP for the past 5 years or so, and I'm taking a look at C#, which I last used 5-6 years ago.&lt;/p&gt;

&lt;p&gt;A lot has happened, it seems.&lt;/p&gt;

&lt;p&gt;One of the greatest pains was threading issues (locks and mutexes, ugh) and it looks like &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;await&lt;/code&gt; will make for a more painless experience in that department, so that's good.&lt;/p&gt;

&lt;p&gt;The platform and the new .NET Core run-times are now cross-platform with Linux and Mac support, so that's a huge plus.&lt;/p&gt;

&lt;p&gt;But where's the simple, elegant, straight-forward, no-frills, no-bells, no-whistles HTTP kernel I'm looking for?&lt;/p&gt;

&lt;p&gt;These past years, with the PSR-7 HTTP model, and PSR-15 middleware model, I've grown accustomed to a very simple and elegant HTTP abstraction consisting of a few interfaces and a trivial middleware stack - I build everything from the ground up with a DI container at the center of everything, which provides me with a huge degree of freedom, flexibility, control and ease of use, with very few moving parts, easy debugging, and nothing to get in the way of handling any special case or requirement.&lt;/p&gt;

&lt;p&gt;Everything I can find for C# looks overly complex, bloated - everything seems to be based on the idea of "standard architecture" with a bunch of hooks and configuration that lets choose from lots of tailored options and plug things in.&lt;/p&gt;

&lt;p&gt;After the success we've had with PSR-7/15, after seeing how happy my fellow developers are working with something much more simple and open, frankly, it would feel like a huge setback, going back to the kind of "fill in the blanks" architecture of "web" frameworks (way too broad!) that we put of with before we discovered things like Express.js, PSR-15 and similar middleware stacks on other platforms.&lt;/p&gt;

&lt;p&gt;All I really want is a simple Request and Response model, and a very basic &lt;code&gt;Request =&amp;gt; Response&lt;/code&gt; middleware abstraction (e.g. PSR-15's &lt;code&gt;HandlerInterface&lt;/code&gt; would do nicely) that plugs into a simple HTTP Host that does the hard work.&lt;/p&gt;

&lt;p&gt;Surely there has got to be something like that for C#/.NET Core?&lt;/p&gt;

&lt;p&gt;Why am I not finding it?&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>php</category>
      <category>question</category>
    </item>
  </channel>
</rss>
