Monthly Archives: March 2024

DEPENDENCY INJECTION IN ASP.NET CORE

EXPLOIT DEPENDENCY INJECTION OF ASP.NET CORE Let's start with a picture that shows us a car engine, look at how many small parts there are. If engineers decided to make so many small components, it is because each one has a different life cycle from the others. Take spark plugs for example, they have a different life cycle than the engine, and the designers decided that through an interface represented by the threading, the spark plug should not be melted into the engine but easily replaced by simply unscrewing the old one and housing the new one. In this [...]

By |2024-03-03T08:47:20+00:00March 3, 2024|0 Comments

DATA ACCESS WITH ADO.NET PART ONE

DATA ACCESS WITH ADO.NET CREATE A SQLLITE DATABASE The time has come to use a relational database, and if we use a database it is because we want to persist our application data in a durable way. For this project we will use SQLite which is a very lean, file-based technology that does not require any prerequisites to be installed. We'll use a database-first approach first we'll create the database and tables then we'll go in with the C# code. THE MYCOURSE.DB DATABASE The database should remain private, no one should download it so the best place to place [...]

By |2024-03-04T20:39:18+00:00March 4, 2024|0 Comments

DATA ACCESS WITH ADO.NET PART TWO

DATA ACCESS WITH ADO.NET LOADING MULTIPLE RESULT TABLES INTO A DATASET Let us see how it is possible to load multiple DataTables into a DataSet. In this example, two are loaded since there are two queries, But even more can be uploaded. This is the code: The code has been commented on. PROTECT APPLICATION FROM SQL INJECTION When we select a course by requiring that the id be passed to us, that value is actually part of the query string or a form, and the user has the power to modify it. Suppose there is a [...]

By |2024-03-09T04:55:07+00:00March 9, 2024|0 Comments

ENTITY FRAMEWORK CORE PART ONE

ENTITY FRAMEWORK CORE WHAT IS THE PURPOSE OF AN ORM AS AN ENTITY FRAMEWORK CORE New technologies such as ORMs have been introduced over the years, and Entity Framework Core is one of them. They are not alternative technologies to ADO.NET but are based on ADO.NET, operating at a slightly higher level. They allow us facilities, such as working with an object model, querying our data with strongly typed queries. ORMs since they work at a higher level introduce a small performance cost, if our site has thousands of users and we do not want to introduce performance cost, [...]

By |2024-03-11T19:36:21+00:00March 11, 2024|0 Comments

ENTITY FRAMEWORK CORE PART TWO

ENTITY FRAMEWORK CORE CREATE LINQ QUERIES Linq is the other technology we will use to query the database and get back course information. Linq does not send SQL queries, we have actual C# methods that will allow us to select, filter, sort data. Linq allows us to query any data source. Let's look at the interface IEnumerable<T>. The minimum requirement for using Linq is that the class implements sequential access with IEnumerable<T>. Let's start with Where, which is an Extension Method that can filter a list of items it receives [...]

By |2024-03-14T15:35:40+00:00March 14, 2024|0 Comments

ENTITY FRAMEWORK CORE PART THREE

ENTITY FRAMEWORK CORE MAPPING CLASSES OF ENTITIES The Database First approach is not fully supported by Entity Framework and this is because the Tool we used is destructive. Suppose we want to add a column to one of our tables, however, we want the same column to be found in the corresponding entity class, if we run the previously used Tool again, all entity classes would be overwritten causing us to lose any changes we made. So CAUTION if we create a new column in the database we must be the ones to manually map the corresponding property in [...]

By |2024-03-16T22:06:44+00:00March 16, 2024|0 Comments

THE CONFIGURATION IN ASP.NET CORE MVC

THE CONFIGURATION IN ASP.NET CORE MVC ACCESS CONFIGURATION VALUES WITH THE ICONFIGURATION SERVICE Configuration is a service that will allow us to keep the application's operating parameters out of the C# code. We will keep them in a JSON file without being forced to recompile the application after a change. That way if we sold the application to a customer they could change the configuration without knowing the inner workings. We create an appsettings.json file, the application is already set up to read values from this file, of course if it is present. Here is the code for getting [...]

By |2024-03-18T20:45:39+00:00March 18, 2024|0 Comments

THE LOGGING IN ASP.NET CORE

LOGGING IN ASP.NET CORE MVC USE THE LOGGING SERVICE The logging service, which as usual we receive in the constructor of one of our components, allows us to write a line of text with parameters when events occur in our application that we find interesting. We decide what where and when to write in this log, information that will be useful when the application is put into the production server. The Logging service relies on providers to output the rows written in the log, if the provider supports Structured Logging we can filter the rows based on placeholders. [...]

By |2024-03-22T05:18:54+00:00March 22, 2024|0 Comments

CACHING IN ASP.NET CORE

CACHING IN ASP.NET CORE As we have seen connecting to a database takes some time; the better the hardware resources of the server on which the application resides, the more contained this time will be. However powerful a machine may be, there is still a physical limit that will be reached with so many users using the application. When it comes to that there are several solutions to put into practice such as vertical scalability, or horizontal, let's put two machines so that both can serve users. The solution of scalability works, however, our application requires more resources and [...]

By |2024-03-24T19:52:04+00:00March 24, 2024|0 Comments

SEARCH IN ASP.NET CORE

SEARCH IN ASP.NET CORE LEVERAGE MODEL BINDING TO RECEIVE USER INPUT Now we are going to look at a very important part which is how to receive input from our users. Let's start by talking about model binding which is a convention-based mechanism that is very simple and intuitive to use that allows us to collect user input and use it in the Actions of our Controllers. As we said model binding is based on conventions, instead of id we could choose another name, the important thing is that the template name matches the parameter name. [...]

By |2024-03-26T20:52:50+00:00March 26, 2024|0 Comments
Go to Top