<?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 Orbis Alonzo Gutierrez on Medium]]></title>
        <description><![CDATA[Stories by Orbis Alonzo Gutierrez on Medium]]></description>
        <link>https://medium.com/@orbisalonzo?source=rss-977cfd246ed------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Orwlp3zZfDvK6ivP.jpg</url>
            <title>Stories by Orbis Alonzo Gutierrez on Medium</title>
            <link>https://medium.com/@orbisalonzo?source=rss-977cfd246ed------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 20:08:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@orbisalonzo/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[IEnumerable, IQueryable and List in .NetCore C# Tips]]></title>
            <link>https://medium.com/@orbisalonzo/ienumerable-iqueryable-and-list-in-netcore-c-tips-45ec731bd4?source=rss-977cfd246ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/45ec731bd4</guid>
            <category><![CDATA[net-core]]></category>
            <category><![CDATA[linq]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[ienumerable]]></category>
            <category><![CDATA[csharp]]></category>
            <dc:creator><![CDATA[Orbis Alonzo Gutierrez]]></dc:creator>
            <pubDate>Thu, 09 Apr 2020 19:20:55 GMT</pubDate>
            <atom:updated>2020-04-09T19:20:55.577Z</atom:updated>
            <content:encoded><![CDATA[<h3>IEnumerable, IQueryable and List in .NetCore C# Tips</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0t9bLNlLRnn0b_hct02DdQ.png" /></figure><p>Hi guys, in this new post I want to talk to you about something interesting and a little confusing about the enumerations.</p><p>Many times, and it happened to me on multiple occasions, we only use List and in the worst case IEnumerable, but I come to tell you where you should use the main enumerations, lists and others. In turn, why should you use IQueryable in your LINQ queries.</p><h3>Let’s start with IEnumerable&lt;TEntity&gt;</h3><p>This enumeration is the parent enumeration of those already mentioned,<br>it is good to use IENUMERABLE &lt;TEntity&gt; when we are going to iterate data and we don’t need to modify values ​​of the same enumeration.</p><h3>LIST&lt;TEntity&gt;</h3><p>Use list when apart from iterating data you have to modify the enumeration or your list of objects, this is a little heavier so using it takes a little performance from your app.</p><h3>IQueryable&lt;TEntity&gt;</h3><p>Use this enumeration when you need to query a database, it is more recommended to use it as follows</p><p>// result already becomes an IQueryable &lt;TEntity&gt;<br>var result = _dbcontext.entity;<br>to then be able to use this in the following way<br>result = result.where (expression);<br>result = result.where (expression)<br>result.ToList ();</p><p>When we call a database entity automatically the entity becomes IQueryable to be able to apply for example the corresponding Where (expression) or any other type of filter.</p><p>It is important to know that when we are making the filters with the entity in IQuerable, the data of our entity are not called yet until we execute the .ToList() statement, so our performance increases.</p><p>Instead if we do the following:</p><p>var result = _dbContext.entity.ToList ();<br>result.Where (expression);</p><p>We are subtracting performance from our because we are doing a select of everything (ToList ()) and then we are doing a Where (expression) so then we are filtering in the list, which subtracts performance from our app.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45ec731bd4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implement UnitOfWork pattern and Implement with Generics!!]]></title>
            <link>https://medium.com/@orbisalonzo/implement-unitofwork-pattern-and-implement-with-generics-968f613fdc6b?source=rss-977cfd246ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/968f613fdc6b</guid>
            <category><![CDATA[unitofwork]]></category>
            <category><![CDATA[generics-programming]]></category>
            <category><![CDATA[net-core]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <dc:creator><![CDATA[Orbis Alonzo Gutierrez]]></dc:creator>
            <pubDate>Tue, 31 Mar 2020 19:04:49 GMT</pubDate>
            <atom:updated>2020-03-31T19:21:19.605Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YWg2TmUvAkk3CMJHOsW_Vg.png" /></figure><p>Welcome to my new post, today I want to talk to you about how to implement the UoW design pattern if you do not know what it is, I leave you the link to <a href="https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application"><strong><em>microsoft</em></strong> </a>so that you can understand what it is and re-read the post, as well as implement the UoW of generic way and avoid modifying the UoW layer.</p><p>Important to take into account, I will leave one to the example repository, but this repository is not implemented in layers because the purpose of this post is to implement UoW so that you do not take the structure of this project as an example, if you want a good project structure you I invite you to see my previous <a href="https://medium.com/@orbisalonzo/best-practices-of-c-and-netcore-2020-3f536bbd9e7c"><strong><em>post</em></strong></a>, then having said all this let’s start!</p><h3>UnitOfWork</h3><p>In this example we have 1 class that contains 3 interfaces and services, I don’t just do this because it is an example, always remember to use good practices.</p><p>These services each have the same method that returns 1 string with only a few differences, they can download the repository at the end of the post so that they can be clearly analyzed.</p><p>TestOneService receives 1 dbcontext<br>TestTwoService receives 1 dbContext and an IOptions<br>TestThreeService receives 1 dbContext</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*549bTaqcfjp9Z4k6rLYU4Q.png" /><figcaption>Example of services</figcaption></figure><h3>Unitofwork Implementation</h3><p>This would be the basic implementation of this pattern where we have the IUnitOfWork interface and its service which will be injected in the startup.cs and each service will be injected in the constructor of some controller.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AUttwD971nA2CawC9Yjc7A.png" /><figcaption>interfaces</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i15YLCikVfbuqcgoq8re9Q.png" /><figcaption>Implementation</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z8h9-jvXsqPwIo_V3DY5AQ.png" /><figcaption>Inyection example</figcaption></figure><h3><strong>Use</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P4SLyGGSinFSb2VE10uVQg.png" /><figcaption>Use of IUoW</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wtZUzYgXAkaVJosfKM5Dow.png" /><figcaption>Result</figcaption></figure><p>If we see the implementation is correct everything is fine so far, but what happens? , every time we create a service we will have to add it to the IUnitOfwork interface and then create its respective instance in the service, this is fine is not a problem but if we would have the possibility to create this generically we would not have to be doing this process and we We would save many lines of code, right? In that case I have implemented this in a generic way, read on and you will notice. :)</p><h3><strong>Generic Implementation</strong></h3><p>Before continuing you should know that perhaps it is not always feasible to implement it in the following way, so each stage should be evaluated where it would be possible to implement said pattron and this generic way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aOXuUWcxSbmqFXDO1G_rpA.png" /><figcaption>Interface</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tIhpi14ZgEgVs6ErM0Whzw.png" /><figcaption>Implemantacion</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SRqNgJ87tciGNPl8D8SEcg.png" /><figcaption>We inject the service in this way because we need to pass parameters to it, so we can do it with typeof.</figcaption></figure><p>If you set the service as generic when calling the service as well as the dbcontext that I use in a generic way indicating that a generic dbContext can be used as well, this dbContext must correspond to the dbContext injected into the service.</p><p>Later there is a method called getRepository that receives a class that would be where the service interface is implemented and returns a TService that would be the service that passes the GENERICREPOSITORY class as a parameter, from here the class is called (Activator.CreateInstance (typeof (TClass), _context)), indicating that a runtime intact of the class passed as generic is created and its overload to the constructor, which would be the (_context).</p><p>In other words, depending on the number of parameters that our service receives, we would have to pass the parameters indicated by the position after indicating the TClass, if we had a second parameter we would have to do the following:</p><p>(Activator.CreateInstance (typeof (TClass), new object [] <br>{ <br>param1,<br>param2<br>})).</p><p>Then if we continue observing we will have an overload of said method for those services that need more than 1 parameter.<br>What this method does is the same as the first one, only it receives a list of objects in the order that the injected service receives it in its constructor.</p><p>but what happens here ?, here we have parameters.insert (0, _dbcontext) what happens is that I indicate that the dbcontext of these services should be injected in the first position of your service if you wanted you could add it as a parameter too, but in I put this case only at the beginning as the main parameter and we return the service</p><h3>Case of use</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*bLZpKA8tkaBe-TJTKfXuRQ.png" /><figcaption>interface</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kszOrLpotQStUv8KV9DsjQ.png" /><figcaption>Result</figcaption></figure><p>If we look we have the same result in a generic way, but what if our service needs more parameters ?, then here is the next case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZMYD2h-lYo8FHJpbJ8SHCA.png" /><figcaption>interface</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VGriyWfCVccw7Dhkj3T9tg.png" /><figcaption>Result</figcaption></figure><p>So far the post has been, any questions or comments you can leave below the post, do not forget to like it and if you want to see the repository as I mentioned at the beginning press the following link =&gt; <a href="https://github.com/Orbis25/GenericImplementation-UnitOfWork">GITHUB</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=968f613fdc6b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Best Practices of C# and .NetCore 2020]]></title>
            <link>https://medium.com/@orbisalonzo/best-practices-of-c-and-netcore-2020-3f536bbd9e7c?source=rss-977cfd246ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f536bbd9e7c</guid>
            <category><![CDATA[net-core-3]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[net-core]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <dc:creator><![CDATA[Orbis Alonzo Gutierrez]]></dc:creator>
            <pubDate>Sat, 28 Mar 2020 16:55:51 GMT</pubDate>
            <atom:updated>2020-03-31T15:56:44.461Z</atom:updated>
            <content:encoded><![CDATA[<h3>Best Practices of C# and .NetCore 2020</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*f0O1MpaG9iSPkahGqmY00g.png" /></figure><p>Today, there are many design frameworks and patterns that can help us solve certain problems related to architecture, best practices and scalability of our projects in .netCore.</p><p>Today I will tell you about the architecture and good practices that I use to develop my projects in .netCore</p><p>We start with the architecture of my projects.<br>1- Architecture based on N-layers<br>2- Repository pattern<br>3- UnitOfWork</p><p>In my projects I create several layers or class libraries where I have separated the data layer, the logic layer and the web layer that the project would be as such and in some cases I create a layer for the UnitOfWork and in this way remove this dll.</p><p>Example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*n3c31H5hstb7LORRlYci2w.png" /></figure><p><strong>Design patterns<br></strong>1 — MVC<br>2 — Repository<br>3 — UnitOfWork</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dsUwIRVPb9z-dyvw4NXYZQ.png" /><figcaption>Modify Operations (Repository Pattern)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i_xAwstautHbWQR3cuKy3Q.png" /><figcaption>Querable Operations</figcaption></figure><p><strong>UnitOfWork</strong></p><p>According to <a href="https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application">Microsoft </a>:<br>The repository and unit of work patterns are intended to create an abstraction layer between the data access layer and the business logic layer of an application. Implementing these patterns can help insulate your application from changes in the data store and can facilitate automated unit testing or test-driven development (TDD).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rCOqjgOCLn28AnHFAD2mvg.png" /><figcaption>Interface</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iZ5o9-9VpqO8fX1OVIeq3A.png" /><figcaption>Class service</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*zdwCh_cyxwvYa2os69_-lQ.png" /><figcaption>In your controller</figcaption></figure><p><strong>Async and await</strong></p><p>It is important to know how this works, from the most basic example an asynchronous operation allows a new thread to open in the application, preventing our entire application from working only under the same thread and avoiding problems later on by overloading only one thread.</p><p>This is why it is essential to use asynchronous operations throughout our application.</p><p>public async Task &lt;bool&gt; MyMethod () {}</p><p><strong>Nameof ()</strong><br>Use this method when you need to write a string, I generally use it to redirect to the actions of my controller, this way when you rename an action you won’t have to go to change the name again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*xi483D0KAFkFD2W1hXFM3Q.png" /><figcaption>Example</figcaption></figure><p><strong>Extensions Methods</strong></p><p>Use extensions methods so you don’t have to create the code again when you need to extend methods of a class,<br>the clearest example that I can generate and that is also a good practice is to create extender methods for the Startup.cs class</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c1--zlOfMac8B1PYav9KVQ.png" /><figcaption>StartupExtensions.cs</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h_VJk9qtcQs0nKjMcNzngg.png" /><figcaption>Startup.cs</figcaption></figure><p><strong>Seed methods</strong></p><p>This is optional but it is important, if you have an application that needs some data to work, it is good that you create seeds methods, for example if you need an admin user to exist in the app, it is good that you use these methods, if you do not know it, enter Microsoft documentation for more information on how to implement it.</p><p><strong>Apis</strong></p><p>When you create apis you can use the aforementioned architecture but the following is important:</p><p>1-Swagger<br>2-Routing</p><p><a href="https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-3.1&amp;tabs=visual-studio"><strong>Swagger </strong></a>creates a documentation for you based on the models and endpoints of your api.</p><p>Routing it is important that you use the following in your controllers<br>so you don’t have to be renaming each controller and you don’t have to put the path name in your actions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*9onLIZBetUKBDUlzF-PdBA.png" /></figure><p><a href="https://docs.automapper.org/en/stable/"><strong>AutoMapper</strong></a></p><p>This package is important to know, I use it a lot in my apis to avoid sending all the data to my controllers and avoid exposing simple data with less code, in the same way we can make projections in the database to bring only the necessary data.</p><p>In conclusion these are the best practices that I have implemented so far, maybe there are more that I have overlooked but so far this is the first count of the best practices to implement in .netcore.</p><p>My Github : <a href="https://github.com/Orbis25">https://github.com/Orbis25</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f536bbd9e7c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>