model-binding (all stored as name-value pairs)
Form Values
Route Values
Query Strings
if model-binding fails, MVC doesn't throw an error (ModelState.IsInvalid)
ViewData
Un-typed Key-Value Dictionary
ViewData["cheese"] = CheeseData.GetAll()
ViewData["cheeses"] = cheeses (sets Data in ViewData on controller)
@ViewData["cheeses"] = to retrieve in View
These 2 are equivalent:
@model ListCheeseMVC.Models.Cheese....then use "Model" throughout cshtml
ViewBag
Dynamic-Object which is wrapper around the ViewData
ViewBag.CheeseData.GetALl()
ViewModel
Model class to be used in view
Allow our views to-be "strongly-typed". Good for Form-Validation
@* *@ are razor view comments
Tag Helper
label asp-for="Name" /label... generates a label for Name property of "ViewModel"
Error Messages in View
div asp-validation-summary = "All"
in ViewModel: [Required(ErrorMessage="")]
override page styles
@RenderSection("overrideStyles", false)
then in view... @Section overrideStyles {put style tags in here}
handling hidden inputs
input class="form-control" asp-for="classProperty" type="hidden"
good for preserving properties on an object back and forth through view
are used to specify methods and properties that a derived class will have access to.
Like a contract...if a class implements an interface...then the interface guarantees the class has access to that method.
Doesn't contain Code or Data
Big role in Abstraction and Styles
Used to specify related behaviors that may be common across unrelated classes
similar to interfaces BUT can't be instantiated. Frequently partially or never implemented
abstract classes cannot be instantiated
Can contain code or data
A class can inherit from only one abstract class (but can implement multiple interfaces)
Can specify methods as virtual to force a derived class to implement their own definition.
If you have classes that will have a lot of the same code/methods...go with abtract class instead of interfaces
Containing Class doesn't hold implementation (derived classes do that)
Derived classes must implement all derived methods.
Example: A Person abstract class that has a PrintName() method in addition to some data such as default value for an age.
should-be used to collect and specify behavior by related classes.
you IMPLEMENT an interface while you EXTEND an abstract class
Sealed Modifier prevents it from derived or overriding of methods
Sealed can only be applied to methods that are overriding "virtual" methods of the base class.
slightly faster because of run-time optimizations
Used to create data or functions that don't need to be instantiated
only contain static members
inherently sealed
Can't be instantiated
allow you to enforce Type Safety by letting you tailor a method or class to a precise data-type
example: Array Class to store list of users or products and then when you use them you can use them as Users or Products (don't have to do any unboxing)
abstraction allows making relevant information visible
are usually implemented as Abstract classes or Interfaces
...when classes have different functionality while sharing the same interface
Blue Ray Disc player(is the interface) able to play DVD(object) or CD(object)
Employee class...another class inherits from it(contractor)..then a permanent Employee class...SO they have different CalculateSalary classes (polymorphic)
Overloading with your methods is also a form of polymorphism
creating multiple methods in a class with same name but different parameters and types is called method overloading...is an example of compile time polymorhpism which is done at compile time.
Run Time polymorphism would be Method overriding
Related features
Encapsulation prevents access to implementation details.
encapsulation ex: setting stuff as private inside classes
when an object or class is based on a parent class (taking on its characteristics)
CLR Common Language Run-Time...offers security, memory management, exception handling
FCL (framework class library) sits on top of the CLR
C# compilers create Managed code - garbage collecting, references etc...
Unmanaged code compiles straight to machine code...
...Not portable
...Not managed by the CLR
Boxing is the process of converting a value type to the type object (integer into an object)
Boxed values use more memory and require memory lookups to access.
Unboxing extracts the value from the object
allows your class to no longer be responsible for instantiating its own dependencies
helps to develop loosely coupled code
3 ways - method, constructor,
Derives from the concept of Inversion of Control
Authors of "Elements of Reusable Object-Oriented Software"
Allows applications to perform with CRUD type operations
Provides an obstraction of data so that
Maintains in-memory updates
sends in-memory updates as one transaction to the database
often used with Repository Pattern...similar to how transactions in database are done which can be rolled back.
Monolithic Pros:
Monolithic Cons:
Microservice Pros:
Microservice Cons:
Positive attitudes toward microservices, despite the higher initial cost vs monolthic apps. Aware that microservices tend to perform and scale better in the long run.
Structure the app so that services are independent from each other at the code level, but easy to bundle together as a monolithic app in the beginning. Microservice overhead costs can be delayed until it becomes more practical to pay the price.