Nizamuddin Siddiqui has Published 2307 Articles

How to implement Dependency Injection using Property in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Dec-2020 06:41:09

1K+ Views

The process of injecting (converting) coupled (dependent) objects into decoupled (independent) objects is called Dependency Injection.Types of Dependency InjectionThere are four types of DI −Constructor InjectionSetter InjectionInterface-based injectionService Locator InjectionSetter InjectionGetter and Setter Injection injects the dependency by using default public properties procedure such as Gettter(get(){}) and Setter(set(){}). Examplepublic interface IService{ ... Read More

How to implement Open Closed principle using C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Dec-2020 06:39:48

444 Views

Software entities like classes, modules and functions should be open for extension but closed for modifications.Definition − The Open Close Principle states that the design and writing of the code should be done in a way that new functionality should be added with minimum changes in the existing code. The ... Read More

How to implement Single Responsibility Principle using C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Dec-2020 06:37:34

276 Views

A class should have only one reason to change.Definition − In this context, responsibility is considered to be one reason to change.This principle states that if we have 2 reasons to change for a class, we have to split the functionality in two classes. Each class will handle only one ... Read More

How to get formatted JSON in .NET using C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Dec-2020 06:35:03

3K+ Views

Use Namespace Newtonsoft.Json.Formatting Newtonsoft.Json.Formatting provides formatting options to Format the JsonNone − No special formatting is applied. This is the default.Indented − Causes child objects to be indented according to the Newtonsoft.Json.JsonTextWriter.Indentation and Newtonsoft.Json.JsonTextWriter.IndentChar settings.Examplestatic void Main(string[] args){    Product product = new Product{       Name = "Apple", ... Read More

How to run multiple async tasks and waiting for them all to complete in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Dec-2020 06:33:01

3K+ Views

The Task.WaitAll blocks the current thread until all other tasks have completed execution.The Task.WhenAll method is used to create a task that will complete if and only if all the other tasks have complete. In the 1st example, we could see that when using Task.WhenAll the task complete is executed ... Read More

What is the difference between All and Any in C# Linq?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Dec-2020 06:30:58

2K+ Views

Any() method returns true if at least one of the elements in the source sequence matches the provided predicate. Otherwise, it returns false. On the other hand, the All() method returns true if every element in the source sequence matches the provided predicate. Otherwise, it returns falseExamplestatic void Main(string[] args){ ... Read More

What is dependency inversion principle and how to implement in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 05-Dec-2020 06:29:13

658 Views

High-level modules should not depend on low-level modules. Both should depend on abstractions.Abstractions should not depend on details. Details should depend on abstractions.This principle is primarily concerned with reducing dependencies among the code modules.ExampleCode Before Dependency Inversionusing System; namespace SolidPrinciples.Dependency.Invertion.Before{    public class Email{       public string ToAddress ... Read More

What is proxy design pattern and how to implement it in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 25-Nov-2020 12:19:51

170 Views

The Proxy pattern provides a surrogate or placeholder object to control access to another, different object.The Proxy object can be used in the same manner as its containing objectThe ParticipantsThe Subject defines a common interface for the RealSubject and the Proxy such that the Proxy can be used anywhere the ... Read More

What is Interface segregation principle and how to implement it in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 25-Nov-2020 12:16:41

306 Views

Clients should not be forced to depend upon interfaces that they don't use.The Interface Segregation Principle states that clients should not be forced to implement interfaces they don't use.Instead of one fat interface many small interfaces are preferred based on groups of methods, each one serving one submoduleBefore Interface SegregationExamplepublic ... Read More

What is Facade and how to implement in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 25-Nov-2020 12:14:49

112 Views

The Facade pattern is a simple structure laid over a more complex structure.The ParticipantsThe Subsystems are any classes or objects which implement functionality but can be "wrapped" or "covered" by the Facade to simplify an interface.The Facade is the layer of abstraction above the Subsystems, and knows which Subsystem to ... Read More

Advertisements