<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by CHIBUIKE KENNETH on Medium]]></title>
        <description><![CDATA[Stories by CHIBUIKE KENNETH on Medium]]></description>
        <link>https://medium.com/@chibuikekenneth?source=rss-7c4c663b5db1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*izKhvscPjM8JhW5lO0I0Jw.jpeg</url>
            <title>Stories by CHIBUIKE KENNETH on Medium</title>
            <link>https://medium.com/@chibuikekenneth?source=rss-7c4c663b5db1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 11:50:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chibuikekenneth/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Maybe we should take things easy]]></title>
            <link>https://chibuikekenneth.medium.com/maybe-we-should-take-things-easy-cf15130b9629?source=rss-7c4c663b5db1------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf15130b9629</guid>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[mental-health]]></category>
            <category><![CDATA[poetry]]></category>
            <category><![CDATA[storytelling]]></category>
            <dc:creator><![CDATA[CHIBUIKE KENNETH]]></dc:creator>
            <pubDate>Thu, 10 Dec 2020 13:45:00 GMT</pubDate>
            <atom:updated>2021-03-26T22:34:14.710Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*izKhvscPjM8JhW5lO0I0Jw.jpeg" /></figure><p>This is far from a “Year in Review” or whatever you call it kind of story. Although the year is getting to an end, everyone would admit that 2020 has been quite a year. I’m literally burnt out, and it&#39;s quite surprising writing this because It&#39;s been difficult to concentrate or work on any serious project lately.</p><p>With recent events, at one point we must have asked ourselves, <strong>Why does anything even exist at all?</strong> <strong>what exactly are we doing?</strong>. Most people would say: “If you cannot imagine why there is something rather than nothing, you are probably a realistic person. Still, you exist, so there must be something wrong with such a viewpoint”.</p><p>Are we resisting life? Am I?. The more you resist your circumstances, the more stress you bring into your life.</p><p>If you resist everything, your life becomes filled with stress. You do not like your job, Stress. You do not like your family, Stress. You do not like your classmates, Stress. You do not like yourself. Stress. Nothing that you see or encounter meets your approval. This is a recipe for illness.</p><p>Maybe we should learn to accept life rather than resist it. <strong>Maybe life was meant to be simple</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*8RrJu-usWsci21BUJmplTQ.jpeg" /><figcaption>Image Source memegenerator.net</figcaption></figure><p><strong>Maybe we should take things easier</strong>, I won’t deny, there has been a lot of Progress, in almost every aspect of my life, especially in times like this and a year like 2020. I’m grateful to God almighty. I have learned a lot from life over the years.</p><p>I think I’ll give myself a chance to be simple, take a break, relate more with family and friends, meet new people, explore more with nature. Take breaks occasionally from computers.</p><p>Maybe I should take things easy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf15130b9629" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dependency Injection, The Big Picture]]></title>
            <link>https://blog.devgenius.io/dependency-injection-the-big-picture-e4ae1e13c87d?source=rss-7c4c663b5db1------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4ae1e13c87d</guid>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[aspnetcore]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[csharp]]></category>
            <dc:creator><![CDATA[CHIBUIKE KENNETH]]></dc:creator>
            <pubDate>Thu, 29 Oct 2020 21:12:13 GMT</pubDate>
            <atom:updated>2024-04-07T01:27:35.526Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BuHIN8vIbz3pINIg0qq7FA.png" /></figure><h3><strong>What is Dependency Injection?</strong></h3><p>There are quite a lot of definitions out there on dependency injection (DI), and its use cases. Dependency Injection is another piece of a puzzle in software engineering, widely used as a design pattern in a lot of web frameworks and applications.</p><p>I like to define <strong>Dependency Injection</strong> as a <strong><em>design pattern</em></strong>, and technique which implements <strong><em>Inversion of Control</em></strong><em> </em>(IOC), whereby an object receives other objects that it depends on.</p><p>So many buzz words right? Let&#39;s get a clearer picture. 😅</p><p>First, think of <strong><em>design patterns</em></strong> as solutions to general problems that software developers face during software development.</p><p><strong>Inversion of Control</strong> (IOC) on the other hand, is a very broad or generic term in software engineering. In simple terms, <em>it means controlling how components and classes behave, thus, as the name suggests, it is used to invert different kinds of controls in object-oriented design to achieve loose coupling</em>.</p><p>Inversion of control is a little bit tricky, you can follow this <a href="https://martinfowler.com/articles/injection.html#InversionOfControl"><strong>writeup</strong></a><strong> </strong>from Martin fowler to get a more clear example.</p><p>Now, let&#39;s go back to what I mentioned earlier in the definition, which says <strong><em>dependency injection</em></strong> as a technique that implements <strong>Inversion of Control</strong>. With Dependency injection, <strong><em>implementations are passed into an object</em></strong> through constructors, services lookups, setters, etc, which the object will ‘depend’ on in order to behave correctly.</p><h3>Types of Dependency Injection (DI)</h3><p>There are three types of Dependency injection, and we are going to see how it’s used.</p><p><strong>Constructor Injection:</strong> This is widely used in the implementation of Dependency Injection. In the constructor injection, the injector supplies the service (dependency) through the class’s constructor when creating the instance of that class.</p><p><strong>Property Injection (Setter Injection):</strong> In property injection, the injector supplies the dependency through a public property of the class.</p><p><strong>Method Injection (Interface Injection):</strong> In the method injection, dependencies are provided through methods. This method can be a class method or an interface method.</p><h4>Constructor Injection</h4><p>As mentioned earlier, the dependencies are provided through a client’s class constructor. Although most of the examples here will be written in C#, it’s a general-purpose language, and easy to understand in terms of <strong>Object-Oriented (OO)</strong> principle.</p><p>Let&#39;s use a real-world scenario for better understanding, Let&#39;s imagine a school, basically, a school is where we go to acquire knowledge, by learning what involves ‘that’ of which we want to acquire or get more understanding for. And we can do so by attending classes, etc.</p><p>Create an Interface <strong>ISchool.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3878d56fbc8ca60477976ca31742974a/href">https://medium.com/media/3878d56fbc8ca60477976ca31742974a/href</a></iframe><p><strong><em>ISchool</em></strong> interface has a method definition called <strong><em>Learn.</em></strong> Create a Class <strong><em>School</em></strong>, which takes in <strong><em>ISchool </em></strong>Interface as a parameter in its constructor.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd859aa2e2f8ab72fbdae8042fa38946/href">https://medium.com/media/dd859aa2e2f8ab72fbdae8042fa38946/href</a></iframe><p>Now let’s add two popular universities (Havard University and Oxford University), both obviously fall under the School category, and Must inherit from <strong><em>ISchool </em></strong>Interface.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81a790633b60d674babbaf5108c437ec/href">https://medium.com/media/81a790633b60d674babbaf5108c437ec/href</a></iframe><p>With the above classes, let&#39;s see Dependency Injection in action. 😋</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/acee7ac296304aedc99260ff0375974a/href">https://medium.com/media/acee7ac296304aedc99260ff0375974a/href</a></iframe><p>Notice that for each instance of the <strong><em>School</em></strong> class, which we can as well call the container class, we are passing a new instance of the class we require, in this case, <em>HavardUniversity</em>, and <em>OxfordUniversity</em>. Which enables <strong><em>loose coupling.</em></strong></p><blockquote>The important thing to note here is that the the <strong>School class </strong>accepts the <strong>ISchool </strong>interface as a parameter in it’s <strong><em>constructor </em></strong>for the <strong><em>depencency.</em></strong></blockquote><pre>private readonly ISchool _school;        <br>public School(ISchool school)    <br>{        <br>   this._school = school;    <br>}</pre><h4>Property Injection</h4><p>As defined earlier, the injector supplies the dependency through a public <strong>property </strong>of the class. Let’s see a good example of this, from our previous code sample.</p><p><strong><em>Property Injection</em></strong> can be achieved alongside <strong><em>Constructor Injection,</em></strong> by setting the default as <strong><em>Constructor Injection</em></strong>. Recall in the <strong><em>School Class </em></strong>we declared a property <strong><em>_school</em></strong>, which is of type <strong>ISchool Interface.</strong></p><pre>private readonly ISchool _school;</pre><p>Now, to fully achieve <strong><em>property injection</em></strong> here, we need to modify this property, we can change it to a public method, and also, it shouldn’t be a <strong><em>read-only </em></strong>type. See the example below.</p><pre>public ISchool _school { get; set; }</pre><p>Notice the <strong><em>get-set</em></strong> methods. Previously, the <strong><em>_school </em></strong>property was a <strong><em>read-only</em></strong> type, which only uses <strong><em>get.</em></strong></p><p>Another way to achieve <strong><em>property injection, </em></strong>which is the normal way, and in this case, the Constructor Injection is actually not set as the default Injection pattern.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4cb1adeea05b4a7627b11fe869c42345/href">https://medium.com/media/4cb1adeea05b4a7627b11fe869c42345/href</a></iframe><p>So, Injecting the dependency via a property will look like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e81b9de4239ed7fda5d4c724d6324861/href">https://medium.com/media/e81b9de4239ed7fda5d4c724d6324861/href</a></iframe><p>You can see that the property <strong>school </strong>of the <strong>School </strong>class can now be assigned different instances of either Havard or Oxford Universities, which is exactly where the injection takes place.</p><h4>Method Injection</h4><p>Dependencies are provided through methods, by passing this dependency as a method argument. This method can be a class method or an interface method.</p><p>Let&#39;s see a simple example of the above definition. Also, using our previous example, let&#39;s modify the code to further show how method injection takes place.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2d91aeca6c14f05b54f5f635580d29b/href">https://medium.com/media/a2d91aeca6c14f05b54f5f635580d29b/href</a></iframe><p>Notice we are passing the <strong>ISchool </strong>interface as an argument to <strong><em>AttendClass()</em></strong> method.</p><p><strong><em>Method Injection</em></strong> is different from other types of DI patterns such that the injection doesn’t happen in a <em>Composition Root</em> but, rather, dynamically at invocation.</p><p>A <strong>Composition Root</strong> is a (preferably) unique location in an application where modules are composed together.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7aabc8fa793d998d01f16932c4afc975/href">https://medium.com/media/7aabc8fa793d998d01f16932c4afc975/href</a></iframe><blockquote>To summarize the types of <strong>Dependency injection</strong>, we can say that a student needs a school, and <strong><em>Constructor Injection</em></strong> provides the student with a university upfront, and they can’t change. <strong><em>Property injection</em></strong> lets someone become a student without picking a university, and they can change universities, but probably not often. <strong><em>Method injection</em></strong> makes a student pick which university they’re going to each time they attend a class!.</blockquote><p>In C#, using modern web frameworks like <a href="https://docs.microsoft.com/en-us/aspnet/core/?view=aspnetcore-3.1"><strong>ASP.NET Core</strong></a>, Dependency Injection is a built-in feature, and its supports are not limited to the middleware alone, but also in other parts of the framework like Controllers, Views, and Model, etc.</p><p>Further details on how <strong><em>Dependency Injection</em></strong> works in <strong>Asp.Net Core</strong> is to note that this is made possible with the use of <strong><em>Containers (IOC Containers).</em></strong></p><h4>So what is an IoC Container?</h4><p>Remember that the whole point of <strong>IoC </strong>is that we shouldn’t need to wire up our dependencies manually, thus Dependency Injection implements <strong>IoC.</strong></p><p>The <strong>IoC container</strong> creates an object of the specified class and also injects all the dependency objects through a constructor, a property, or a method at run time and disposes it at the appropriate time. This is done so that we don’t have to create and manage objects manually.</p><p>So in frameworks likes <strong><em>Asp.Net Core</em></strong>, we register what we call <strong><em>providers</em></strong> and the <strong><em>container (Ioc Container)</em></strong> does the dependency injection for us.</p><h3><strong>Advantages of Dependency Injection</strong></h3><p>Dependency Injection has quite a lot of advantages and so many use cases as well, but let&#39;s take a look at a few.</p><h4><strong>Loosely coupled architecture</strong></h4><p>loose coupling means that objects should only have as many dependencies as is needed to do their job — and the dependencies should be few. Furthermore, an object’s dependencies should be on interfaces and not on “concrete” objects, when possible.</p><h4>Easily testable code with different mock implementations</h4><p>Dependency injection increases a component&#39;s testability. When dependencies can be injected into a component it is possible to inject mock implementations of these dependencies. Mock objects are used for testing as a replacement for a real implementation.</p><h4><strong>More readable code</strong></h4><p>It’s easier to see what dependencies an object has, or whatever your use case is. Making the code more readable.</p><h3>References</h3><p><a href="https://martinfowler.com/articles/injection.html#InversionOfControl"><em>Inversion of Control: Martin fowler</em></a><em>, </em><a href="https://www.tutorialsteacher.com/ioc/dependency-injection"><em>DI explanation: Tutorials teacher</em></a></p><h4>Summary</h4><p>These are a few basic explanations I could come up with concerning Dependency Injection, and I do hope this helps. I tried as much as possible to explain in very simple and plain steps, but if there’s any concern, please do let me know.</p><p>Also, Please leave a clap if you found this helpful. 😃</p><p>Thanks to Lionell Park for thoroughly checking out the code samples as well.</p><p><a href="http://chibuikekenneth.github.io/"><em>(chibuikekenneth.github.io)</em></a>, <a href="https://github.com/Chibuikekenneth"><em>(github)</em></a>, <a href="https://twitter.com/chibuikekenn"><em>(twitter)</em></a><em> 💂</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4ae1e13c87d" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/dependency-injection-the-big-picture-e4ae1e13c87d">Dependency Injection, The Big Picture</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>