Skip to content

Commit

Permalink
small tweaks in blog autogenerated thing
Browse files Browse the repository at this point in the history
  • Loading branch information
hjwp committed Feb 19, 2024
1 parent b4e4a2e commit cc04e4d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ <h1> Repository and Unit of Work Pattern</h1>
request.</p>
<p>What does a unit of work look like?</p>
<div class="codehilite"><pre><span></span><code><span class="k">class</span> <span class="nc">SqlAlchemyUnitOfWorkManager</span><span class="p">(</span><span class="n">UnitOfWorkManager</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;The Unit of work manager returns a new unit of work. </span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;The Unit of work manager returns a new unit of work. </span>
<span class="sd"> Our UOW is backed by a sql alchemy session whose </span>
<span class="sd"> lifetime can be scoped to a web request, or a </span>
<span class="sd"> long-lived background job.&quot;&quot;&quot;</span>
Expand All @@ -232,7 +232,7 @@ <h1> Repository and Unit of Work Pattern</h1>


<span class="k">class</span> <span class="nc">SqlAlchemyUnitOfWork</span><span class="p">(</span><span class="n">UnitOfWork</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;The unit of work captures the idea of a set of things that</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;The unit of work captures the idea of a set of things that</span>
<span class="sd"> need to happen together. </span>

<span class="sd"> Usually, in a relational database, </span>
Expand Down
6 changes: 3 additions & 3 deletions blog/2017-09-19-why-use-domain-events.html
Original file line number Diff line number Diff line change
Expand Up @@ -354,20 +354,20 @@ <h2>Mapping our requirements to our domain</h2>
<div class="codehilite"><pre><span></span><code><span class="k">class</span> <span class="nc">MessageBus</span><span class="p">:</span>

<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Our message bus is just a mapping from message type</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Our message bus is just a mapping from message type</span>
<span class="sd"> to a list of handlers&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">subscribers</span> <span class="o">=</span> <span class="n">defaultdict</span><span class="p">(</span><span class="nb">list</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">handle</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;The handle method invokes each handler in turn</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;The handle method invokes each handler in turn</span>
<span class="sd"> with our event&quot;&quot;&quot;</span>
<span class="n">msg_name</span> <span class="o">=</span> <span class="nb">type</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span>
<span class="n">subscribers</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">subscribers</span><span class="p">[</span><span class="n">msg_name</span><span class="p">]</span>
<span class="k">for</span> <span class="n">subscriber</span> <span class="ow">in</span> <span class="n">subscribers</span><span class="p">:</span>
<span class="n">subscriber</span><span class="o">.</span><span class="n">handle</span><span class="p">(</span><span class="n">cmd</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">subscribe_to</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="n">handler</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Subscribe sets up a new mapping, we make sure not</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Subscribe sets up a new mapping, we make sure not</span>
<span class="sd"> to allow more than one handler for a command&quot;&quot;&quot;</span>
<span class="n">subscribers</span> <span class="o">=</span> <span class="p">[</span><span class="n">msg</span><span class="o">.</span><span class="vm">__name__</span><span class="p">]</span>
<span class="k">if</span> <span class="n">msg</span><span class="o">.</span><span class="n">is_cmd</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">subscribers</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
Expand Down
2 changes: 1 addition & 1 deletion blog/2019-04-15-inversion-of-control.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ <h2>Removing cycles by inverting control</h2>
<p>There are a few ways to tackle a circular dependency. You may be able to extract a shared dependency into a separate
module, that the other two modules depend on. You may be able to create an extra module that coordinates the two modules,
instead of them calling each other. Or you can use inversion of control.</p>
<p>At the moment, each module calls each other. We can pick one of the calls (let&rsquo;s say <code>A</code>&lsquo;s call to <code>B</code>) and invert
<p>At the moment, each module calls each other. We can pick one of the calls (let&rsquo;s say <code>A</code>&rsquo;s call to <code>B</code>) and invert
control so that <code>A</code> no longer needs to know anything about <code>B</code>. Instead, it exposes a way of plugging into its
behaviour, that <code>B</code> can then exploit. This can be diagrammed like so:</p>
<p><img src="/images/why-di/plugin.png" alt="B plugging into A" /></p>
Expand Down
2 changes: 1 addition & 1 deletion rss.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Simple patterns for building complex apps
</description>
<link>https://www.cosmicpython.com</link>
<lastBuildDate>Tue, 02 Aug 2022 10:10:54 -0000</lastBuildDate>
<lastBuildDate>Mon, 19 Feb 2024 15:08:06 -0000</lastBuildDate>
<pubDate>Sat, 4 Jan 2020 19:15:54 -0500</pubDate>
<atom:link href="https://cosmicpython.com/rss.xml" rel="self" type="application/rss+xml" />

Expand Down

0 comments on commit cc04e4d

Please sign in to comment.