Posts

Showing posts from July, 2022

Understanding MVC with the Help of Design Patterns

Most of us are familiar with the architecture called MVC - Model-View-Controller and how to implement it, but how many of us know that MVC follows compound pattern when seen from a design pattern point of view. Understanding MVC with Design Patterns Here we are basically trying to understand MVC from the Design pattern point of view. MVC as the name suggests consists of three major components namely Model, View and Controller. Responsibilities of the classes are given below: Model : Holds the Application logic and the associated data. View : Responsible for Representing data contained in the Model. Controller : Responsible for taking actions based on User Interaction and calling necessary APIs in the Model. Controller is essentially sandwiched between the Model and the View and can interact with both. Let us try to understand based on the functionalities of each of these components the pattern they might be following. Model basically has the application logic and maintains the state of...

Why IEnumerable is required in C# ? All you need to know | Explained with Example

Image
  Use of IEnumerable in C# code is not new and We have already seen it being used in many places where we are dealing with Collection. Either it will be present as the return type and/or as parameter type.  What is IEnumerable in C#? IEnumerable is an Interface in C# which provides the capability to iterate over the Collection or in other words Enumerate over the collection which implements it. Why IEnumerable? Following are the reasons/should be the reasons for using IEnumerable  It allows the use of For-each loop over the collection which is kind of a range based for loop in C#. It abstracts the under lying data structure which holds the actual data. Modification of the collection data is prevented when collection is exposed as IEnumerable. Second point is the most important one for the use of IEnumerable, where it can act as a generic collection and the underlying data structure is not exposed outside. We can see these in action with the below example: Sample Code: ...

Creating RESTful Minimal WebAPI in .Net 6 in an Easy Manner! | FastEndpoints

Image
  We might have developed Web APIs using MVC Controllers where we used to give Route Path Attributes to the Controller and  to identify individual methods we used to provide Actions in the Route. With the Controller approach we need to write boiler plate code in separate files which deals with the Configuration of the Web Service. Those who have worked in Node js would be aware of how easy it is to create a Web API and expose different Endpoints without the need of so much boiler plate code. Here we are going to discuss of similar approach for creating a Web API in .Net6 using FastEndpoints. Under the hood it uses Minimal API concept which tries to reduce the dependencies required to achieve a particular task. This approach is more suitable in the case of Microservice Architecture where we want to keep the dependencies to minimum. Must Read : Fluent API and Data Annotations What are FastEndpoints? FastEndpoints is a Framework compatible with .Net 6 which allows to build a...