.NET CORE Flashcards
(36 cards)
What is Model Binding (ASP.Net) and why is it important?
Model binding is asp.net is essentially the middle man between your incoming http request and your api controller. It is important because it binds the incoming http request with the proper controller action method.
What are the fundamentals that a developer should consider when working to wire up model binding correctly?
Make sure your routing is correct to whatever the name of your specific service is. The correct interface is being provided in the constructor so that when the api controller is instantiated it has the correct methods that need the logic implemented for. Each service needs to have proper error handling so that errors do not get swallowed, meaning the error doesn’t come back in a response. Proper error handling includes multiple catches such as sqlexception, argumentexception, or exception. Have proper null checks in place so you can return an error that specifies if data isn’t passed in.
What are the differences between an API Controller and a “regular/view” Controller in .Net?
API controllers are specialized in returning data. Json without serialization. Normal controllers are used to return views.
When creating a new controller, what class do you inherit from?
The basecontroller or baseAPIcontroller
Describe the main differences or considerations between the JS and C#.
C# is a static typed language meaning it’s type checking at compile and can’t run without you fixing them. JavaScript is dynamically typed so you can attempt to run it even if you have errors. C# also requires you to define the data type of your variables whereas JavaScript doesn’t.
What is the generic name of the library used in .Net that is used to communicate with Databases?
ADO.NET. Namespcaes system.data, system.data.SqlClient,
What are the .Net objects and classes used to communicate and execute commands at the database?
Dbcommand Class.
What is a Null Reference Exception?
A NullReferenceException is thrown when you try to access a member on a type whose value is null. A NullReferenceException typically reflects developer error and is thrown usually when they have forgotten to instantiate a reference type.
What is an MVC View?
Model-View-Controller View is a display using the model class object. It is a software class and contains a template and data form to produce a response for the browser.
What is a Model?
A model represents the shape of data as public properties and business logic as methods. Think of like your USERS or ADDUSERREQUEST.
What are C# extension methods?
A method added to an object after the original object was compiled. The modified object is often a class, a prototype or a type. Example: when you implement an interface and can use the methods in it.
What are Interfaces?
Interfaces are contracts that defines methods or properties that an implementing class must provide implementing logic for.
What is an abstract class and is this different than an interface?
An abstract class allows you to create functionality that subclasses can implement or override. An interface only allows you to define functionality, not implement it. And whereas a class can extend only one abstract class, it can take advantage of multiple interfaces.
Can you create an instance of an abstract class?
No you cannot because it does not have a complete implementation. The purpose of an abstract class is to function as a base for subclasses. it acts like a template or an empty structure you should extend and build on it before use.
What are the principles of object-oriented programming?
Encapsulation - Restricting access to methods and attributes of certain classes (private). Preventing accidental modification of data or unwanted changes. Abstraction - extension of encapsulation, process of selecting data from a larger pool to show only the relevant details to the object. (Only certain data needed to create account on dating app, things such as favorite food or hobbies isn’t needed) Inheritance - the ability for one object to acquire some/all properties of another object. Such as updateUser : addUser Polymorphism - A way to use a class exactly like its parent so there is no confusion with mixing types. Example Testdata has methind add(int a, int b, inc ) returns a + b + C. Another class can take a new version named t = new testdata() then get the method and bring in it’s own parameters. t.add(3 + 5 + 8) returns = 16.
What are Generics in .Net
Generics let you tailor a method, class, structure, or interface to the precise data type it acts upon. For example, List
Why are Generics so important?
Performance: Collections that store the objects use boxing and unboxing on data types. A collection can reduce performance. Type Safety: there is no strong type information at compile time as to what is stored in the collection.
In .Net how many classes can one class inherit from?
You can only inherit from one base class.
How do you declare a variable in C#?
You would declare a variable like this: DATATYPE name.
What does it mean to be a strongly typed language?
Static typing is where the type is bound to the variable. Types are checked at compile time.
Dynamic typing is where the type is bound to the value. Types are checked at run time.
A strongly-typed programming language is one in which each type of data (such as integer, character, hexadecimal, packed decimal, and so forth) is predefined as part of the programming language and all constants or variables defined for a given program must be described with one of the data types.
How can you test if an instance of an object implements a particular interface?
if(myObject is IMyInterface) { // object myObject implements IMyInterface }
What is a static member or property in .Net?
Astaticclass is basically the same as a non-static class, but there is one difference: a static class cannot be instantiated. In other words, you cannot use thenewoperator to create a variable of the class type. Because there is no instance variable, you access the members of a static class by using the class name itself. For example, if you have a static class that is named UtilityClass that has a public static method named MethodA, you call the method as shown in the following example: UtilityClass.MethodA();
What does your typical error handling code look like?
try
{
result = services.method(“datatobepassed.com”)
}
catch (Argument ex) { response = new ErrorResponse(ex.Message) base.Logger.LogError(ex.ToString()); } catch (Exception ex) { response = new ErrorResponse(ex.Message)
base.Logger.LogError(ex.ToString());
}
catch (SqlException/whatever specific ex)
{
response = new ErrorResponse($”Generic Error: ${sqlEx.Message}”)
base.Logger.LogError(sqlEx.ToString());
What is the Web.Config/ApplicationSettings.json? What do you use it for?
The web.config/appsettings.json file is an application configuration file used to store configuration settings such as database connections strings, any application scope global variables, etc.