<?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 John Francis on Medium]]></title>
        <description><![CDATA[Stories by John Francis on Medium]]></description>
        <link>https://medium.com/@johnfrancis_84777?source=rss-a0741644c4e6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4az3j8JsU4eLWnYu7-paTA.jpeg</url>
            <title>Stories by John Francis on Medium</title>
            <link>https://medium.com/@johnfrancis_84777?source=rss-a0741644c4e6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 03:53:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@johnfrancis_84777/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[Ninject in Web API 2]]></title>
            <link>https://medium.com/@johnfrancis_84777/ninject-in-web-api-2-d035efa0cd22?source=rss-a0741644c4e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/d035efa0cd22</guid>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[aspnet]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[John Francis]]></dc:creator>
            <pubDate>Sun, 18 Aug 2019 15:55:14 GMT</pubDate>
            <atom:updated>2019-08-18T15:55:14.980Z</atom:updated>
            <content:encoded><![CDATA[<p>In this story, we’re going to integrate Dependency Injection which is Ninject on Web API 2. Ninject is a Dependency Injection Framework that helps us to decouple our services from repositories using interfaces. Assuming you’ve already had an idea how DI works in manual setup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*WCtQvkGmrMyKkZmGIE7pWQ.jpeg" /></figure><p>Here are the items below for able to configure our Web API 2:</p><ul><li>Microsoft.Owin</li><li>Microsoft.Owin.Host.SystemWeb</li><li>Microsoft.AspNet.WebApi.Owin</li><li>Ninject</li><li>Ninject.Web.WebApi</li><li>Ninject.Web.WebApi.OwinHost</li><li>Ninject.Web.Common</li><li>Ninject.Web.Common.OwinHost</li><li>Ninject.Extensions.NamedScope</li></ul><p>We need setup OWIN Startup Class since our Ninject would run under OWIN middleware, take note any framework integration needs to run under by OWIN.</p><p><strong>Configuring Ninject OWIN</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*VCDtYpABX7hX3yz5hQCYHQ.png" /></figure><p>As you can see above Ninject was already integrated into OWIN. The <strong>UseNinjectMiddleware </strong>accepts a parameter <strong>Kernel</strong>. A kernel is a container for all of our <strong>Services</strong> and <strong>Repositories.</strong></p><p><strong>Binding Services and Repositories</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*Xx9reE38-KGTsp8o76Ub2A.png" /></figure><p>Once our module is created we load this into the kernel. <strong>Load</strong> method will handle the instantiation of our objects, so we don’t need anymore to create them one by one.</p><p><strong>Creating Service and Repository</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*kzbMoIeowoEimZ2yqUaUlQ.png" /></figure><p>Our service and repository are already independent of each other. This is only a basic example but in real-world your repository would contain database operations and service would contain business logic.</p><p><strong>Calling Service from Controller</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*-yA2JPFA7RyEbJ_7GX5tsQ.png" /></figure><p>Calling our service is very easy we just need a reference of an interface which is <strong>IUserService </strong>since the interface cannot be instantiated.</p><p><strong>Congratulations!</strong></p><p>You just created Ninject with Web API 2. Remember our API runs synchronously since this is an API we need to make this asynchronously for able to increase the amount of request at the same time with the same resources. Follow my next story about Ninject with Dapper using Web API 2. Thanks :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d035efa0cd22" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Web API 2]]></title>
            <link>https://medium.com/@johnfrancis_84777/building-web-api-2-29d1bf2fecac?source=rss-a0741644c4e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/29d1bf2fecac</guid>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[aspnet]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[John Francis]]></dc:creator>
            <pubDate>Sat, 17 Aug 2019 18:46:41 GMT</pubDate>
            <atom:updated>2019-08-22T01:59:49.942Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Building Web API 2 from scratch</strong></h3><p>In this story, we’ll be building a Web API 2 application. API makes our data fully independent from any application meaning this is can be used by any application that is written in Java, C#, Python or Javascript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gJ-5p9oOy_SdvC49Yg02lQ.jpeg" /></figure><p>Here are a few things I need to discuss.</p><ul><li><strong>Web API</strong></li><li><strong>OWIN</strong></li></ul><p><strong>Web API</strong></p><p>ASP.NET Web API is a framework for building HTTP services that can be consumed by a broad range of clients including browsers, mobiles, and tablets.</p><p><strong>OWIN (Open Web Interface for .Net)</strong></p><p>OWIN helps us to decouple web server from the application framework, also, develop lightweight and modular applications with a possibility of porting them across different web servers.</p><p><strong>Configuring Web API</strong></p><p>Let’s start configuring our Web API by creating an empty Web API project, once the solution is created we’re going to download some packages for OWIN.</p><ul><li>Microsoft.Owin</li><li>Microsoft.Owin.Host.SystemWeb</li><li>Microsoft.AspNet.WebApi.Owin</li></ul><p>After downloading these packages we need an index file called Owin Startup Class which will be the entry point of our application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*qeBKuC8yWFLwvW3MzmXCPA.png" /><figcaption>Owin Startup Class</figcaption></figure><p>As you can see above I configured index file by creating an instance of <strong>HttpConfiguration </strong>which allow us to define what kind of routing will be used on our API. Routing in API is divided into two Conventional and Attribute but on this setup, the attribute routing will be going to use. Since Attribute Routing has a lot of advantages compare to Conventional.</p><ul><li>API Versioning</li><li>Overloaded URI</li><li>Multiple parameter types</li></ul><p><strong>Creating Web API Controller</strong></p><p>Our Owin is already configured, we need to create some methods for our controller which will be tested later by Postman. Postman is a testing ground for API where we can dissect everyone&#39;s API, one good practice is to test first the API before calling this on Single Page Application or MVC to make sure this will not fail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*kjD8owo3OijSOxq_y-bTrQ.png" /><figcaption>UserController</figcaption></figure><p>Make sure you created an empty Web API 2 Controller. As you can above I made a RoutePrefix for our UserController, this helps us to build a different version some scenarios we’ll encounter on developing an API, is to separate version for development and production to avoid conflict of data.</p><p><strong>Testing Web API Controller</strong></p><p>It’s time to test the API, make sure you’ve downloaded the Postman. I’m going to test first the <strong>GetInfo</strong> method which our default route since the route was named to nothing.</p><p><strong>First Scenario (GetInfo)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4bt8nVub0vJ98mZJxlN26g.png" /></figure><p>Don’t forget to put the correct address on Postman and hit the send button to send a request on the server.</p><p><strong>Second Scenario (FindUser)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CdcONriuaWR_On_bG9ga1A.png" /></figure><p>As you noticed on our second method it has a parameter <strong>[FromUri] </strong>meaning the parameters should be a <strong><em>primitive type </em></strong>(int, double, string) Web API tries to get the value from URI of the Http Request.</p><p><strong>Third Scenario (Find-Address)</strong></p><p>The last test for our last method it has a parameter <strong>[FromBody]</strong> meaning the parameters should be a <strong><em>complex type </em></strong>(our own object) Web API tries to get the value from Body of the Http Request. Don’t forget to check the raw radio button under Body tab and choose JSON(application/json) for testing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_SGL84KXdls1kLkL2zwhhg.png" /></figure><p><strong>Congratulations!</strong></p><p>You just created a basic Web API let’s make this advance by adding Dependency Injection Framework to make our code more maintainable and readable. Thanks for reading! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29d1bf2fecac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dependency Injection in C#]]></title>
            <link>https://medium.datadriveninvestor.com/dependency-injection-in-c-cf4e5a659204?source=rss-a0741644c4e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf4e5a659204</guid>
            <category><![CDATA[c]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[John Francis]]></dc:creator>
            <pubDate>Sun, 13 Jan 2019 15:04:04 GMT</pubDate>
            <atom:updated>2019-08-21T15:30:44.303Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*Rz9h5rC6u57vCSxr4Qyl-A.jpeg" /></figure><p>Many Software Developers are struggling with how to handle their services and helpers in the right way. As your application gets bigger, your responsibility in handling dependencies gets bigger too.</p><p>This story is intended for all developers who don’t have much experience in handling dependencies.</p><p><a href="https://www.datadriveninvestor.com/2019/01/23/which-is-more-promising-data-science-or-software-engineering/">Which is More Promising: Data Science or Software Engineering? | Data Driven Investor</a></p><p>As long as you have experience in Object-Oriented Programming, we’re good to go.</p><p>Here are a few things I need to discuss.</p><ul><li><strong>Dependency Injection</strong></li><li><strong>Tight Coupling</strong></li><li><strong>Loose Coupling</strong></li></ul><h3><strong>What is Dependency Injection?</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*Bb0L_5Cc1V-o11JXys8dqg.png" /></figure><p><strong>Dependency Injection</strong> is a programming technique whereby one object supplies the dependencies of another object. This helps us to follow single responsibility principles.</p><h3><strong>Interface</strong></h3><p>We will use interfaces to break dependencies within our classes. This makes our classes depends on interfaces. This is essential when using Dependency Injection this saves us a lot of time and code.</p><h3>Service</h3><p>All the dependencies that we’re creating are called <strong>Service</strong>. This can be Create, Read, Update, Delete operation, computation or upload functionality that you will use over the time of development.</p><h3><strong>Client</strong></h3><p>The client is the one who is going to use our the Service.</p><h3><strong>Using Dependency Injection</strong></h3><p>First I’m going to create an interface named <strong>IJourneyService</strong>. It has a <strong>void</strong> method</p><p>named <strong>Go() </strong>since we’re just returning a message.</p><pre>public interface IJourneyService{</pre><pre>    void Go();</pre><pre>}</pre><p>I created also two Services named <strong>Bike</strong> and <strong>Car </strong>which implement <strong>IJourneyService </strong>interface. This will inherit the <strong>void</strong> method which is <strong>Go()</strong></p><pre>public class Bike : IJourneyService{</pre><pre>   public void Go(){</pre><pre>     Console.WriteLine(&quot;I&#39;m going to use my Bike&quot;);</pre><pre>   }</pre><pre>}</pre><pre>public class Car : IJourneyService{</pre><pre>   public void Go(){</pre><pre>      Console.WriteLine(&quot;I&#39;m going to use my Car&quot;);</pre><pre>   }</pre><pre>}</pre><p>Our services already created now it’s time to create our Client class that will be going to use our services.</p><pre>public class JourneyClient : IJourneyClient</pre><pre>{</pre><pre>    private IJourneyService journey;<br>    public JourneyClient(IJourneyService journey){</pre><pre>       this.journey = journey;<br>    }</pre><pre>    public void ServeGo(){</pre><pre>      this.journey.Go();<br>    }</pre><pre>}</pre><p>As you can see here our Client has a constructor that accepts an instance of the class that implements <strong>IJourneyService </strong>since the interface cannot be instantiated, also it implements <strong>IJourneyClient </strong>interface to serve our method from <strong>IJourneyService.</strong></p><h3>Example</h3><pre>namespace DI</pre><pre>{</pre><pre>    class Program</pre><pre>    {</pre><pre>        static void Main(string[] args)</pre><pre>        {</pre><pre>            Bike bike = new Bike();</pre><pre>            Car car = new Car();</pre><pre>            JourneyClient jc = new JourneyClient(bike);</pre><pre>            jc.ServeGo();</pre><pre>        }</pre><pre>     }</pre><pre>}</pre><p>Our client is already instantiated but the constructor expected an instantiated class which implements <strong>IJourneyService. </strong>We can pass any objects here it constructor as long as the instantiated object implements <strong>IJourneyService </strong>and then we called the <strong>ServeGo() </strong>method to ride on a Bike or Car.</p><h3><strong>Problem</strong></h3><p>What if your Dependencies get bigger? Do you think we still need to create an instance of each class every time we need it? No way. That’s the time we’ll use the Dependency Injection Framework which is <strong>Ninject </strong>it allows us to adjust our code easily based on the business needs and expectation.</p><p>Stay tuned on my next tutorial which is Dependency Injection using Ninject on ASP.Net Web API. 👌</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fb2a0d6%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2Fb2a0d6%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/0707f5c806284d01a4a13c7b13a91ce3/href">https://medium.com/media/0707f5c806284d01a4a13c7b13a91ce3/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf4e5a659204" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/dependency-injection-in-c-cf4e5a659204">Dependency Injection in C#</a> was originally published in <a href="https://medium.datadriveninvestor.com/">DataDrivenInvestor</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>