Factory Method Pattern In C#


Definition Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.   Frequency of use: High     UML class diagram       Participants   The classes and objects participating in this pattern are: Product  (Page) defines the interface of objects … Continue reading Factory Method Pattern In C#

Advertisements

Abstract Factory Pattern In C#


Definition Provide an interface for creating families of related or dependent objects without specifying their concrete classes. Frequency of use: High UML class diagram Participants The classes and objects participating in this pattern are: AbstractFactory  (ContinentFactory) declares an interface for operations that create abstract products ConcreteFactory   (AfricaFactory, AmericaFactory) implements the operations to create concrete product objects … Continue reading Abstract Factory Pattern In C#

Custom Validation in ASP.NET Web API


We should never trust any input to our applications, so we need validate all of them The problem is that we want our validation to be performed in the API layer, and not make the clients responsible for implementing their own validation. In other words, we need to do the following: Validate all incoming requests. … Continue reading Custom Validation in ASP.NET Web API

Difference between var and dynamic in C#


Introduction The type keyword 'var' was introduced in C# 3.0 (.NET 3.5 with Visual Studio 2008) and the type 'dynamic' was introduced in C# 4.0 ( .NET 4.0 with Visual Studio 2010). Let us see the difference between these two Background Variables declared with var are implicitly but statically typed. Variables declared with dynamic are dynamically typed. … Continue reading Difference between var and dynamic in C#

DataAnnotations – ForeignKey Attribute


ForeignKey attribute can be applied to properties of a class. Default Code-First convention for ForeignKey relationship expects foreign key property name match with primary key property. Consider the following example. public class Student { public Student() { } public int StudentID { get; set; } public string StudentName { get; set; } //Foreign key for … Continue reading DataAnnotations – ForeignKey Attribute