Showing posts from April, 2022

Default Interface Methods in C#

An Interface in C# programming language is defined as an abstract type used to specify the behavior of a class. An interface in  C#  is a blueprint of a class. A  C#  interface contains static constants and abstract methods. The interface in  C#  is a mechanism to achieve abstraction. There can be only abstract methods in the  C#  interface, not the method body. It is used to achieve abstraction and multiple inheritance in  C# . In other words, you can say that interfaces can have abstract methods and variables. It cannot have a method body. …

How to Solve ASP.NET Core Error: System.InvalidOperationException Unable to resolve service for type

ASP.NET Core supports the dependency injection (DI) software design pattern, which is a technique for achieving Inversion of Control (IoC) between classes and their dependencies. When the built-in dependency injection functionality is trying to create a type, it tries to resolve all of the constructor parameters. If it can’t resolve one of the parameters, it’ll throw a variation of exceptions, one of them is the following System.InvalidOperationException: System.InvalidOperationException: Unable to resolve service for type 'MyProject.Mode…

Solid Principles in C# - Explore the Open Closed Principle

From the five solid principles, the Open Closed Principle has been the hardest for me to understand and apply in my C# and ASP.NET MVC projects. Some time ago, however, I came across some code that I had written years ago that made me think this is clearly violating the Open Closed Principle. I was planning to reuse this code in the project I was currently working on, but I realized that I would have to rewrite it to adhere to OCP in order to achieve my goal of writing clean code that fits with my design and flexibility goals. The case – pro…

JavaScript Escape Quotes

A JavaScript string consists of zero or more characters surrounded by quotes. JavaScript can misunderstand a literal quote enclosed inside single quotes, which is why the literal quote must be escaped with a backslash /. In this post, we are going to explore different JavaScript solutions to escape quotes and special characters. JavaScript Escape Quotes - Example 1 var text = 'I hope we\'ll see you at the party next Saturday' ; console .log( text ); //Results: "I hope we'll see you at the party next Saturday" Same …

Load More
That is All