Sarthak Notes
Sarthak Notes
SINGLETON PATTERN
Singleton design pattern is gives us the you know
so basically whenever there is a need that we
want only single object of a class throughout the
application then we can use singleton design
pattern
CONTENT NEGOTIATION
Content negotiation is the mechanism that is used
for serving different representation of resource to
the same URI to help the user to specify which
representation is best suited for the user for
example which document language, which image
format.
REMOTE VALIDATION
We have multiple validations attributes in mvc if
we want to validate same input based on
database value or server values then we can use
this remote validation , remote validation works
with ajax it will hit the server for validation
without re-loading the page
MODELBINDING / MODELBINDERS
Whatever the values are passed by views to the
action method at the time of retrieving those
values passed from view to action method model
binder helps us to retrieve those values
CONSUME WEB API IN MVC
To consume Web API in MVC we can use
HttpClient class in MVC controller.
HttpClient sends a request to the Web API and
receives a response.
Then we can convert response data to a model
and then render it on a view.
OAUTH
Open authentication is a type of token
authentication it allows an end users account
information used by third party services such as
Facebook without exposing users username and
password.
STATIC CONSTRUCTOR
Static constructors are used to initialize static
fields of a class.
Static constructors are called only once regardless
of how many instances of the class are created.
STATIC CLASS
Static class provides centralized and maintainable
approach. static class can only contain static
data members, static methods, and a static
constructor.It is not allowed to create objects
of the static class. Static classes are sealed,
you cannot inherit a static class from another
class
DEADLOCK
Deadlock occurs when two or more processes lock
the separate resource
ANON TYPE
Anonymous type basically type without name. to
handle the anonymous type we use var keyword
ANON ATTRIBUTE
In mvc we have a attribute called as allow
anonymous attribute. which can use if we want
access action method without authentication
without authorization at that time I have seen
anonymous attribute
SP
Stored procedure helps us to reduce network
traffic . helps us to reduce sql injection.
MAGIC TABLE
We have magic table like inserted or deleted
which we use inside a trigger. we call them
magical tables because we don’t insert record into
them record gets automatically inserted or
deleted
ORM
stand for object relational mapper. this
technique used for converting data between c#
object and relational database
CURSOR
A cursor in SQL is a temporary work area
created in system memory. when a SQL
statement is executed.
We can use if we want to operate the table row
by row basis . cursor are not good for
performance
CORS
Cross origin resource sharing is a browser security
feature that restricts cross origin http request that
are initiated from scripts running in the browser.
if our rest api receives non simple cross origin http
request you need enable cross support
SOLID PRINCIPLE
Solid principal gives us some standard way to
design better application architecture
Solid is acronym
S -for single responsibility , o- for open close
principle , l – for lyscom principle , I – interface
segregation , d – for dependency segregation.
CLR
Comman language runtime clr managed
execution environment that is the part of .net
framework
GARBAGE COLLECTOR
The garbage collector manages the allocation and
release of memory.
SEALED CLASS
Sealed class can not get inherited consider we
have two classes base class and derived class
Base class is seled class then sealed class can not
get inherited by the derived class .
EXTENSION METHOD
Extsion method allows us to add new method in
existing class or in the structure without
modifying the source code of the original type
namespace Program {
public static class Demo {
public static int myExtensionMethod(this string str) {
return Int32.Parse(str);
}
}
class Program {
static void Main(string[] args) {
string str1 = "565";
int n = str1.myExtensionMethod();
Console.WriteLine("Result: {0}", n);
Console.ReadLine();
}
ENUM
We can replace integral constants using enum
Advantages - code readable , maintainable
LAZY LOADING
Loading data on demand
MVC LIFECYCLE
A mvc lifecycle is a series of steps or events used
to handel some type of request or change an
application state
ROUTING WEB API /MVC
Web api routing is similar to the asp.net mvc
routing .it routes on incoming http request to a
particular action method on a web api cantroller
RANK FUNCTION
Ranking function we use to give the row number
or rank to the table. we have different types of
ranking functions like row number, dense rank
and entile function all ranking functions works
differently
YIELD KEYWORD
Yield keyword helps us to do custom stateful
iteration over .Net collections. We can customize
iteration through a collection without creating a
temporary collection. Which will helps us to save
some memory.
TUPLE
A tuple is an ordered sequence, immutable, fixed
size and of heterogeneous objects. Tuple can be
used as return type of a method where we cannot
use anonymous types as return type.
DELEGATE
Delegates are type safe function pointers.
Delegates allow methods to be passed as
parameters. Delegates are used to define callback
methods. Delegates signature should get match
with method signature that’s why it is called as
type safe.
EXCEPTION HANDLING
Exceptions are nothing but runtime unforeseen
errors of an application. It is always a bad practice
in showing yellow screen to end user which
contains some application specific information.
This information is meaningless for a normal user
whereas useful for a hacker to hack your
application. So it is always recommended to do a
proper exception handling.
INTERFACE
Interface is a contract that defines the signature
of the functionality. It looks like a class but has no
implementation. It has only empty definition of
methods, functions, events, and indexer. Interfacs
provide forced implementation
GENERICS
Generics help to separate logic and data type to
increase reusability.we can create a class whose
data type can be defined on run time.
GAC
GAC (Global Assembly Cache) is where all
shared .NET assembly resides.
The Global Assembly Cache (GAC) is a folder
in Windows directory to store the . NET
assemblies that are specifically designated to
be shared by all applications executed on a
system
UNIT TESTING
Unit testing is a component of test tdd which is
test driven development
Unit testing is the first level of testing which is
done by the developer to test small unit of source
code.
Unit testing is done by developer in our project
before we handover the project to the qa team.
we write the unit cases also . we are using n unit
framework for the unit testing
Egger loading
Loading data even if user not using the data
PARTIAL VIEW
Part of page if I want to create some part of page
on our main page . partial view are mainly use for
reusability and maintainability. partial view we
can render on another partial method and on
main view also.Partial view returns mvc html
string
PARTIAL CLASS
Using partal class we can split class into multiple
physical files for example entity framework in
entity framework whatever models get generated
those are partial classes.partial class is created
using a partial keyword
VIEW PORT
The viewport is the user's visible area of a
web page. The viewport varies with the
device, and will be smaller on a mobile phone
than on a computer screen
PARAMETERIZED CONSTRUCT
A construct which has at least one parameter
is called parameterized construct.using this
type of construct we can initialize each
instance of the class to different values
Class Employee{
Int EmpId;
String EmpName;
Int EmpAge;
Public Employee(Int EmpId, String EmpName,
Int EmpAge)
{
this EmpId = EmpId;
this EmpName = EmpName;
this EmpAge = EmpAge;
}
Static void Main(string[]args)
Employee Sarthak = new
Employee(11,”Sarthak”,24);
Console.ReadLine();}
COPY CONSTRUCT
The construct which creates an object by
copying variables from another object is called
a copy construct . the purpose of copy
contruct is to initialize a new instance to the
value of existing instance
PARAMS
Param is an important keyword in C#. It is
used as a parameter which can take the
variable number of arguments
namespace AccessSpecifiers
{
class Program
{
// User defined function
public void Show(params int[] val) // Params Paramater
{
for (int i=0; i<val.Length; i++)
{
Console.WriteLine(val[i]);
}
}
// Main function, execution entry point of the program
static void Main(string[] args)
{
Program program = new Program(); // Creating Object
program.Show(2,4,6,8,10,12,14); // Passing arguments of variab
le length
}
EXCEPTION MVC
We can use try catch block to handle the
exceptions but in mvc we have a filter concept
we have exception filter so we can use that
handle error attribute handle error filter to
handle the exception but in our project we
have done with the global error handling we
have created our own custom filter
implementing the exception filter and so all
type of exceptions are handled by that
particular custom handle error attribute which
we have created
TRIGGERS
triggers gets automatically fired. against the
command against the action with whom we have
created that trigger we have different types of
triggers basically dml triggers, ddl triggers triggers
triggers are very useful execute query without
actually writing them without actually calling them.
triggers has lots of advantages basically because
don't need to call the trigger explicitly also in
trigger we have a magical table inserted and
deleted using we can get those data which is
going to be deleted or inserted from the table
INDEX
Index helps the query to run faster we have
two types of index method cluster and non
cluster index we can create only one clustered
index but we can create multiple non
clustered index over the table
MEDIA TYPE FORMATTER
Web API supports multiple message formats so
if we want to configure our API for particular
message format for communication then we can
use a media type formatter by default Web API
support Jason and XML format but if we want to
customize then we can create our own custom
media media type formatter also
LOOP
Loop allows you to execute a single statement
or a block of statement repitatively
ABSTRACT CLASS
The abstract keyword is use to create abstract
class . an abstract class is incomplete and
cannot be instantiated an abstract class can
be used as base class. An abstract class
cannot be sealed
DYNAMIC KEYWORD
dynamic keyword checks the type at runtime if
we have any type which we are not sure in
compile time then we can use dynamic
keyword this will check type in runtime so
compiler will not give us any error
INHERITANCE
inheritance allows us to transfer common
attributes and methods of existing class
transfer common attributes and methods from
parent class to child class .inheritance
provides re-usability by allowing us to extend
an existing class
BUNDALING
Bundaling is a technique to improve
performance by reducing the number of
request to the server instead of a fetching all
resources one by one we can create a bundle
and featch that bundle in a one single request
MINIFICATION
Minification performs a variety of
different code optimizations to scripts or
css, such as removing unnecessary
white space and comments and
shortening variable names to one
character.
PRIVATE CONSTRUCTOR
Private constructor is a special instance
constructor which is used in a class that
contains static member only.
when we use private constructor inside a
class then we cannot create the object of that
class then anywhere in the application
basically it restricts due to inaccessibility.
private constructor or we mostly used to
implement the singleton design pattern
SIMPLE CONSTRUCTOR &
TYPES
A special method of a class or a structure in
object oriented programming language that
initialise a newly created object of that type
AREA
An area is a small unit of mvc web application
which has the same folder structure model,
view ,controller, as the actual application area
provide a way to partition a large asp.net mvc into
smaller functional groupings if our application is
made of multiple high level functional components
that should be logically separated if I want to
partition in our mvc projects that each functional
area can be work independently when I want to
separate modules to maintain the application and
in asp.net mvc we can have any number of areas
which area has its own control models and views.
in larger application each team can work
independently .area is easy to manage and easy
to read
WEB AIP
API stands for application programming
interface Web API allows user to access a
particular resource using we can build web
pages in different technologies
AJAX HELPERS
Ajax helpers works asynchronous on
view.these are use to get,post data from
controller without refreshing entire page .
ROUTING
Routing is a pattern matching system routing
Match incoming request to particular request
each incoming request is mapped in the route
table
CONVENTIONAL ROUTING
Conventional Routing is a pattern matching
system for URL that maps incoming request
to the particular controller and action method.
We set all the routes in the RouteConfig file.
RouteConfig file is available in the App_Start
folder. We need to register all the routes to
make them operational
ATTRIBUTE ROUTING
As the name implies, attribute routing means
attributes are used to define routes. The
Attribute routing provides more control over
the URIs in our Web API application by
defining routes directly on the actions and
controllers
MVC ARCHITECTURE
Mvs stands for Model views and controllers the
user is requesting user always request to an action
method of controller and then whatever the data or
validation part is there it is done in the model and
then if we want to return the UI so that logic and
controls will be handled by views so the main
request goes to action method of controller action
method takes the data from model it use that
database review and then view returns that html
response which we display on the browser
HTTPSRESPONSE AND
IHTTPACTION RESULT
both we can use to return the response from the
Web API method using http response message
we need to use create response or create error
response methods and we need to explicitly
provide the status code and the response while
returning from the method but using ihttpaction
result we have the methods like okay ,bad request
not found ,unauthorised so we can use this
method directly to return the response without
specifying the status code
RAZOR
Razor is a wave engine. using razor we can
create CSHTML pages and using cshtml
page is we can write C sharp code plus HTML
code
VIEW BAG VIEW DATA TEMP
DATA
View bag is a dynamic property collection
viewdata is key value pair collection temp
data is again a key value pair dictionary
collection we use viewbag and viewdata to
transfer the data from controller to view we
used temp data if we want to transfer the data
from one controller to another controller or
one action method to another action method
EXCEPTION GLOBALLY
If want to handle the exception globally then I
will create a custom exception filter and then I
will register that custom filter in the config file
so that whenever there is a unhandled
exception in any action method then
automatically my exception filter will get
invoked and it will basically help me to handle
exception so we can do the global exception
handling also
SQL INJECTION
sql injection is a attack there are some scenario
which user can inject and execute sum SQL
query from Ui and this can be occurred when
we have be in line queries when we directly use
the input values and use those values in the
query so this problem can be solved and
prevent by using parameterised query and using
stored procedure
TRANSACTIONS
Basically they block of statements but
which make sure that whether we want
to execute all of the queries or non of
queries so there is a chance that either
we can commit the queries else we can
rollback them also. transaction gives us
the behaviour which is like automic
consistent isolated and durable. so
transactions are very important if we
have some dependent queries which we
are writing in the stored procedure
DIFF INTERFACE AND
ABSTRACT CLASS
Interface is totally incomplete and
abstract also whereas in abstract class
we can write incomplite as well as
complete methods also in Interface we
cannot write fields in interface we cannot
write constructors in interface we cannot
write explicit access specifiers to the
interface members
whereas in abstract class we can write
fields we can write constructors also we
can write access specifiers to the
members so as per my understanding
whenever there is any requirement like we
want the different implementation different
method body for all the classes i will go
with interfaces whereas if i want some
common implementations then i will go
with abstract class
MULTIPLE INHERITANCE
Multiple inheritance means base class is
inheriting more than one classes but c
sharp do not support multiple inheritance
because of diamond problem
If we have to achieve multiple inheritance
we can create multiple interface. for
multiple inheritance we can create two
different interfaces and in one class we can
inherit both the interfaces
PROINTERFACE
We have various places where we have
used interfaces mainly we have
implemented repository pattern in our
project where we have use interfaces to
create the signature where we have a
methods to retrieve the entity
information to insert the entity to
update the entity or to delete the entity
apart from it we have implemented
interface to perform given task and given
functionality
PROENCAPSULATION
Encapsulation is a feature used to hide
data outside of that class and we have a
lots of models and classes we have
created in our project like we have
various classes like a farmer class
customer class in this class is there are
some information which I don't want
expose to outside class in that case we
have used in encapsulation
GLOBAL.ASAX
Global.asax file is application configuration
file global.asax file basically inherits HTTP
application class and this global.asax file
contains all the application level events like
application_start application_end this type
of events application level events are there
in global.asax file
BUNDLE.CONFIG
Bundle config basically when we do the
bundling and basically bundling is a
concept where we can merge multiple
JavaScript files or multiple CSS files to
improve the performance it reduces the
number of calls to the server and which
eventually improve the performance so in
bundle config file we actually creates the
bundle and we specifies the file names that
which files are there and which bundle we
want to create so bundle config file has all
the bundle name information and along
with that it has the file names also
HTML HELPERS
HTML Helpers are used in View to render
HTML content. Using html helpers we can
create the UI controls for example we have a
methods like editor for display for or display or
editor for model drop down list or checkbox so
we have lots of extension methods with the
html helper class and we can create our own
we can add methods also we can add our
own custom extension method also to this
html helper class
IOC
Inversion of Control (IoC) means that
objects do not create other objects on which
they rely to do their work.
DYAMIC POLYMORPHISM
dynamic polymorphism we have method
overriding method overriding means in
derived class we can override any method
from the base class and which gives the
benefit that whenever a base class
reference variable points to a derived
class object then in that case it will call
back overridden method
PARALLELISM
for parallelism we can basically use
multithreading or multitasking
programming where we can perform
multiple tasks at the same time
ASYNC AND AWAIT
Async and await keywords are basically
used to create a task so basically async and
await keywords are useful for a
synchronous call which actually improve
the performance so if I want to perform if I
want to call multiple methods at the same
time or if I want to call a method
asynchronously without dependency then I
can use async and await keyword
Main {print 1 ();print2();}
Public async void Print1()
{await Task.Run() = >
For(int i= 1; i<=5; i++)
{Console.WriteLine(i);}
Public async void Print2()
For(int I= 1; i<=5; i++)
{Console.WriteLine(i);}
VIRTUAL KEYWORD
virtual keyboard we use if we want to override that
method in the derived class virtual keyboard
basically indicates that we can override that
method in the derived class .virtual method we can
write in any class as well as virtual method we can
write the implementation also
BASE KEYWORD
base keyword is basically it points to the current
instance of the base class so if we have the
inheritance and if we want to access any members
of base class in derived class then we can use
base keyword to access the members from base
class so using base keyword we can access the
properties fields constructor method also
CUSTOM FILTERS
we can implement the filter interfaces
we can inherit the filter classes and so
one way we can create the custom filter
that we can implement the interface
methods or we can override this action
filter methods in our custom filter class
and we can apply this custom filter
class either on the controller level or
action method level or maybe in our
filter config file so that it will be applied
globally in our project we have used
custom filter also so for exception
handel we have created our custom
exception filter
OVERIDING AND
OVERLADING
we can override a method in derived
class which we have already
declared in the base class whereas
overloading is a concept where we can
have same method name with different
signature we can overload a method
based on number of parameters, order
of parameters, types of parameters or
kinds of parameters overriding is a
runtime polymorphism whereas
overloading is a compile time
polymorphism
SKIP AND SKIP WHILE
Both methods we used to skip the
elements from the collection skip
method expects the count how much
element you want to skip from the
collection whereas skip while method
expects the condition on what basis you
want to skip the elament so that is the
difference between skip and skip while
in skip we are giving the count and in
skip while we are giving the condition
CTE
Common table expression cte we
used to store the result set for
temporary purpose the scope of cte is in
the next immediate statement and we
can use this cte in join or using the cte
we can select or update the records
FILTER.CONFIG
This is used to create and register global MVC
filter, error filter,action filter etc.By default it
contains HandleErrorAttribute filter.
for eg.
Authentication filters (Executed First)
Authorization filters
Action filters
Result filters
Exception filters (Executed Last)
ROUTE.CONFIG
This is used to register various route patterns
for our Asp.Net MVC application. Routing
plays an important role in an ASP.NET MVC
Application in execution flow, it maps request
URL to a specific controller action using a
Routing Table. The RouteConfig. cs file is
used to set routing for the application.
LAMBDA EXPRESSION
Lambda expressions are anonymous
functions that contain expressions or
sequence of operators. All lambda
expressions use the lambda operator.
1. public static class demo
2. {
3. public static void Main()
4. {
5. List<int> list = new List<int>() { 1, 2, 3, 4, 5,
6 };
6. List<int> evenNumbers = list.FindAll(x => (x % 2)
== 0);
7.
8. foreach (var num in evenNumbers)
9. {
10. Console.Write("{0} ", num);
11. }
12. Console.WriteLine();
13. Console.ReadLine();
14.
15. }
CUSTOM VALIDATION