update lecture 15

main
borb 4 days ago
parent a4274969bb
commit 27585976e0

@ -13,10 +13,10 @@
/* buutti.css */
/* @theme buutti */div#\:\$p>svg>foreignObject>section .columns{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:calc(var(--marpit-root-font-size, 1rem) * 1)}div#\:\$p>svg>foreignObject>section .columns12{display:grid;grid-template-columns:1fr 2fr;gap:calc(var(--marpit-root-font-size, 1rem) * 1)}div#\:\$p>svg>foreignObject>section .columns21{display:grid;grid-template-columns:2fr 1fr;gap:calc(var(--marpit-root-font-size, 1rem) * 1)}div#\:\$p>svg>foreignObject>section .columns32{display:grid;grid-template-columns:3fr 2fr;gap:calc(var(--marpit-root-font-size, 1rem) * 1)}div#\:\$p>svg>foreignObject>section .columns23{display:grid;grid-template-columns:2fr 3fr;gap:calc(var(--marpit-root-font-size, 1rem) * 1)}div#\:\$p>svg>foreignObject>section .columns111{display:grid;grid-template-columns:1fr 1fr 1fr;gap:calc(var(--marpit-root-font-size, 1rem) * 1)}div#\:\$p>svg>foreignObject>section .centered{display:flex;flex-direction:column;justify-content:center;text-align:center}div#\:\$p>svg>foreignObject>section .tableborderless td,div#\:\$p>svg>foreignObject>section th{border:none!important;border-collapse:collapse}div#\:\$p>svg>foreignObject>section.extra{background-color:#5d275d;background-image:linear-gradient(to bottom,#401a40,#1d0c1d);color:white}div#\:\$p>svg>foreignObject>section.extra a{color:rgb(145,255,209)}div#\:\$p>svg>foreignObject>section.exercise{background-color:#29366f;background-image:linear-gradient(to bottom,#20636a,#173742);color:white}div#\:\$p>svg>foreignObject>section.exercise a{color:rgb(211,173,255)}
/* @theme l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn */div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]{columns:initial!important;display:block!important;padding:0!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]:after,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]:before,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content]:after,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content]:before{display:none!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]{all:initial;display:flex;flex-direction:row;height:100%;overflow:hidden;width:100%}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container][data-marpit-advanced-background-direction=vertical]{flex-direction:column}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background][data-marpit-advanced-background-split]>div[data-marpit-advanced-background-container]{width:var(--marpit-advanced-background-split,50%)}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background][data-marpit-advanced-background-split=right]>div[data-marpit-advanced-background-container]{margin-left:calc(100% - var(--marpit-advanced-background-split, 50%))}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]>figure{all:initial;background-position:center;background-repeat:no-repeat;background-size:cover;flex:auto;margin:0}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]>figure>figcaption{position:absolute;border:0;clip:rect(0,0,0,0);height:1px;margin:-1px;overflow:hidden;padding:0;white-space:nowrap;width:1px}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content],div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=pseudo]{background:transparent!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=pseudo],div#\:\$p>svg[data-marpit-svg]>foreignObject[data-marpit-advanced-background=pseudo]{pointer-events:none!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background-split]{width:100%;height:100%}</style></head><body><div class="bespoke-marp-osc"><button data-bespoke-marp-osc="prev" tabindex="-1" title="Previous slide">Previous slide</button><span data-bespoke-marp-osc="page"></span><button data-bespoke-marp-osc="next" tabindex="-1" title="Next slide">Next slide</button><button data-bespoke-marp-osc="fullscreen" tabindex="-1" title="Toggle fullscreen (f)">Toggle fullscreen</button><button data-bespoke-marp-osc="presenter" tabindex="-1" title="Open presenter view (p)">Open presenter view</button></div><div id=":$p"><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="1" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn" lang="en-US" class="invert" data-marpit-pagination="1" style="--paginate:true;--class:invert;--heading-divider:5;--theme:l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn;" data-marpit-pagination-total="16">
/* @theme xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v */div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]{columns:initial!important;display:block!important;padding:0!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]:after,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]:before,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content]:after,div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content]:before{display:none!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]{all:initial;display:flex;flex-direction:row;height:100%;overflow:hidden;width:100%}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container][data-marpit-advanced-background-direction=vertical]{flex-direction:column}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background][data-marpit-advanced-background-split]>div[data-marpit-advanced-background-container]{width:var(--marpit-advanced-background-split,50%)}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background][data-marpit-advanced-background-split=right]>div[data-marpit-advanced-background-container]{margin-left:calc(100% - var(--marpit-advanced-background-split, 50%))}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]>figure{all:initial;background-position:center;background-repeat:no-repeat;background-size:cover;flex:auto;margin:0}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=background]>div[data-marpit-advanced-background-container]>figure>figcaption{position:absolute;border:0;clip:rect(0,0,0,0);height:1px;margin:-1px;overflow:hidden;padding:0;white-space:nowrap;width:1px}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=content],div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=pseudo]{background:transparent!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background=pseudo],div#\:\$p>svg[data-marpit-svg]>foreignObject[data-marpit-advanced-background=pseudo]{pointer-events:none!important}div#\:\$p>svg>foreignObject>section[data-marpit-advanced-background-split]{width:100%;height:100%}</style></head><body><div class="bespoke-marp-osc"><button data-bespoke-marp-osc="prev" tabindex="-1" title="Previous slide">Previous slide</button><span data-bespoke-marp-osc="page"></span><button data-bespoke-marp-osc="next" tabindex="-1" title="Next slide">Next slide</button><button data-bespoke-marp-osc="fullscreen" tabindex="-1" title="Toggle fullscreen (f)">Toggle fullscreen</button><button data-bespoke-marp-osc="presenter" tabindex="-1" title="Open presenter view (p)">Open presenter view</button></div><div id=":$p"><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="1" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v" lang="en-US" class="invert" data-marpit-pagination="1" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v;" data-marpit-pagination-total="16">
<h1 id="design-patterns-in-c">Design Patterns in C#</h1>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="2" data-marpit-fragments="3" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn" lang="en-US" class="invert" data-marpit-pagination="2" style="--paginate:true;--class:invert;--heading-divider:5;--theme:l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn;" data-marpit-pagination-total="16">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="2" data-marpit-fragments="3" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v" lang="en-US" class="invert" data-marpit-pagination="2" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v;" data-marpit-pagination-total="16">
<h2 id="overview">Overview</h2>
<ul>
<li data-marpit-fragment="1">The Singleton Pattern</li>
@ -24,10 +24,10 @@
<li data-marpit-fragment="3">Dependency Injection</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="3" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn" lang="en-US" class="invert" data-marpit-pagination="3" style="--paginate:true;--class:invert;--heading-divider:5;--theme:l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn;" data-marpit-pagination-total="16">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="3" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v" lang="en-US" class="invert" data-marpit-pagination="3" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v;" data-marpit-pagination-total="16">
<h2 id="the-singleton-pattern">The Singleton Pattern</h2>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="4" data-marpit-fragments="7" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn" lang="en-US" class="invert" data-marpit-pagination="4" style="--paginate:true;--class:invert;--heading-divider:5;--theme:l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn;" data-marpit-pagination-total="16">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="4" data-marpit-fragments="7" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v" lang="en-US" class="invert" data-marpit-pagination="4" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v;" data-marpit-pagination-total="16">
<h3 id="the-problem">The problem</h3>
<ul>
<li data-marpit-fragment="1">In most cases, it makes no sense to create an instance of a class every time its members need to be accessed
@ -45,7 +45,7 @@
</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="5" data-marpit-fragments="4" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn" lang="en-US" class="invert" data-marpit-pagination="5" style="--paginate:true;--class:invert;--heading-divider:5;--theme:l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn;" data-marpit-pagination-total="16">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="5" data-marpit-fragments="4" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v" lang="en-US" class="invert" data-marpit-pagination="5" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v;" data-marpit-pagination-total="16">
<h3 id="the-solution">The solution</h3>
<ul>
<li data-marpit-fragment="1">The <strong>singleton</strong> class is a class that benefits from all the perks of a non-static class (non-static members, inheritance, referencing…), but only one (or zero) instances of it ever exists during the lifetime of your application</li>
@ -57,7 +57,7 @@
</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="6" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn" lang="en-US" class="invert" data-marpit-pagination="6" style="--paginate:true;--class:invert;--heading-divider:5;--theme:l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn;" data-marpit-pagination-total="16">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="6" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v" lang="en-US" class="invert" data-marpit-pagination="6" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v;" data-marpit-pagination-total="16">
<p>A singleton implementation could look something like this:</p>
<div class='columns' markdown='1'>
<div markdown='1'>
@ -98,14 +98,14 @@
</div>
</div>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="7" data-marpit-fragments="2" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn" lang="en-US" class="invert" data-marpit-pagination="7" style="--paginate:true;--class:invert;--heading-divider:5;--theme:l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn;" data-marpit-pagination-total="16">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="7" data-marpit-fragments="2" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v" lang="en-US" class="invert" data-marpit-pagination="7" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v;" data-marpit-pagination-total="16">
<h3 id="implementing-a-singleton-pattern">Implementing a singleton pattern</h3>
<ul>
<li data-marpit-fragment="1">The exact implementation of the singleton is out of the scope of this course, but it is important to understand that it exists and what its purpose is</li>
<li data-marpit-fragment="2">Multitude of examples for different use cases are available and can be found by googling</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="8" data-marpit-fragments="4" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn" lang="en-US" class="invert" data-marpit-pagination="8" style="--paginate:true;--class:invert;--heading-divider:5;--theme:l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn;" data-marpit-pagination-total="16">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="8" data-marpit-fragments="4" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v" lang="en-US" class="invert" data-marpit-pagination="8" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v;" data-marpit-pagination-total="16">
<h2 id="reflection">Reflection</h2>
<ul>
<li data-marpit-fragment="1">Reflective programming or reflection is the ability for the program to examine or modify its own structure and behaviour</li>
@ -138,7 +138,7 @@ method.Invoke(foo, <span class="hljs-literal">null</span>);
</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="9" data-marpit-fragments="5" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn" lang="en-US" class="invert" data-marpit-pagination="9" style="--paginate:true;--class:invert;--heading-divider:5;--theme:l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn;" data-marpit-pagination-total="16">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="9" data-marpit-fragments="5" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v" lang="en-US" class="invert" data-marpit-pagination="9" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v;" data-marpit-pagination-total="16">
<h3 id="attributes">Attributes</h3>
<ul>
<li data-marpit-fragment="1"><a href="https://learn.microsoft.com/en-us/dotnet/standard/attributes/">Attributes</a> can be used to extend methods, classes, or even entire programs with new <em><strong>metadata</strong></em>
@ -157,7 +157,7 @@ method.Invoke(foo, <span class="hljs-literal">null</span>);
</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="10" data-marpit-fragments="2" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn" lang="en-US" class="invert" data-marpit-pagination="10" style="--paginate:true;--class:invert;--heading-divider:5;--theme:l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn;" data-marpit-pagination-total="16">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="10" data-marpit-fragments="2" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v" lang="en-US" class="invert" data-marpit-pagination="10" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v;" data-marpit-pagination-total="16">
<ul>
<li data-marpit-fragment="1">
<p>Attributes can also have parameters:</p>
@ -192,7 +192,7 @@ method.Invoke(foo, <span class="hljs-literal">null</span>);
</div>
</div>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="11" data-marpit-fragments="2" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn" lang="en-US" class="invert" data-marpit-pagination="11" style="--paginate:true;--class:invert;--heading-divider:5;--theme:l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn;" data-marpit-pagination-total="16">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="11" data-marpit-fragments="2" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v" lang="en-US" class="invert" data-marpit-pagination="11" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v;" data-marpit-pagination-total="16">
<h3 id="custom-attributes">Custom attributes</h3>
<ul>
<li data-marpit-fragment="1">You can write your own <a href="https://learn.microsoft.com/en-us/dotnet/standard/attributes/writing-custom-attributes">custom attributes</a> by inheriting from the <code>Attribute</code> class<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-csharp"><span class="hljs-comment">// This defaults to Inherited = true.</span>
@ -214,10 +214,10 @@ method.Invoke(foo, <span class="hljs-literal">null</span>);
</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="12" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn" lang="en-US" class="invert" data-marpit-pagination="12" style="--paginate:true;--class:invert;--heading-divider:5;--theme:l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn;" data-marpit-pagination-total="16">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="12" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v" lang="en-US" class="invert" data-marpit-pagination="12" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v;" data-marpit-pagination-total="16">
<h2 id="dependency-injection">Dependency Injection</h2>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="13" data-marpit-fragments="4" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn" lang="en-US" class="invert" data-marpit-pagination="13" style="--paginate:true;--class:invert;--heading-divider:5;--theme:l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn;" data-marpit-pagination-total="16">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="13" data-marpit-fragments="5" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v" lang="en-US" class="invert" data-marpit-pagination="13" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v;" data-marpit-pagination-total="16">
<h3 id="the-problem-1">The problem</h3>
<ul>
<li data-marpit-fragment="1">Traditionally, when new objects of classes are instantiated, the consuming class handles the creation of the objects</li>
@ -227,18 +227,19 @@ method.Invoke(foo, <span class="hljs-literal">null</span>);
<li data-marpit-fragment="4">This is called <em><strong>tight coupling</strong></em></li>
</ul>
</li>
<li data-marpit-fragment="5">What we want instead is <a href="https://en.wikipedia.org/wiki/Loose_coupling"><em><strong>loose coupling</strong></em></a>, where components have little or no knowledge about separate components' definitions, and a change in one component doesn't necessitate a change in another</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="14" data-marpit-fragments="4" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn" lang="en-US" class="invert" data-marpit-pagination="14" style="--paginate:true;--class:invert;--heading-divider:5;--theme:l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn;" data-marpit-pagination-total="16">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="14" data-marpit-fragments="4" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v" lang="en-US" class="invert" data-marpit-pagination="14" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v;" data-marpit-pagination-total="16">
<h3 id="the-solution-1">The solution</h3>
<ul>
<li data-marpit-fragment="1">What if, instead of directly creating the objects, they were provided by some interface that takes care of the creation?</li>
<li data-marpit-fragment="2">This way, even if the base class changes, the consuming classes won't care because they only know about the provider</li>
<li data-marpit-fragment="3">This provider is called <em><strong>Container</strong></em>, and the functionality being injected is called <em><strong>Service</strong></em></li>
<li data-marpit-fragment="4">In ASP.NET, this container system is built in</li>
<li data-marpit-fragment="4">In ASP.NET (Microsoft's framework for building web applications), this container system is built in</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="15" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn" lang="en-US" class="invert" data-marpit-pagination="15" style="--paginate:true;--class:invert;--heading-divider:5;--theme:l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn;" data-marpit-pagination-total="16">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="15" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v" lang="en-US" class="invert" data-marpit-pagination="15" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v;" data-marpit-pagination-total="16">
<h3 id="dependency-injection-in-aspnet">Dependency injection in ASP.NET</h3>
<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-csharp"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">HomeController</span> : <span class="hljs-title">Controller</span>
{
@ -252,7 +253,7 @@ method.Invoke(foo, <span class="hljs-literal">null</span>);
}
</code></pre>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="16" data-marpit-fragments="4" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn" lang="en-US" class="invert" data-marpit-pagination="16" style="--paginate:true;--class:invert;--heading-divider:5;--theme:l88lgdm6g50jnf1zbzajbvpkez0urw5hs65fwufujn;" data-marpit-pagination-total="16">
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="16" data-marpit-fragments="4" data-paginate="true" data-class="invert" data-heading-divider="5" data-theme="xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v" lang="en-US" class="invert" data-marpit-pagination="16" style="--paginate:true;--class:invert;--heading-divider:5;--theme:xun2jiy1c7sz4e4w7x1xbtx95u4cs3ssdsjcjf4v;" data-marpit-pagination-total="16">
<h2 id="design-patterns">Design Patterns</h2>
<ul>
<li data-marpit-fragment="1">If the concepts of a singleton and dependency injection flew over your head, don't worry about it</li>

@ -207,13 +207,14 @@ void TraceMethod()
* Many classes change their functionality throughout the development of any project
* This means that also _every single_ consuming class has to change
* This is called *__tight coupling__*
* What we want instead is [***loose coupling***](https://en.wikipedia.org/wiki/Loose_coupling), where components have little or no knowledge about separate components' definitions, and a change in one component doesn't necessitate a change in another
### The solution
* What if, instead of directly creating the objects, they were provided by some interface that takes care of the creation?
* This way, even if the base class changes, the consuming classes won't care because they only know about the provider
* This provider is called *__Container__*, and the functionality being injected is called *__Service__*
* In ASP.NET, this container system is built in
* In ASP.NET (Microsoft's framework for building web applications), this container system is built in
### Dependency injection in ASP.NET

Loading…
Cancel
Save