ref can be considered code smell
readonly
decorate readonly when something should be instantiated only-once
protected
ONLY accesible from its class and derived classes
AVOID if can (use private instead)
internal = only accessible from the same assembly (same Program)
protected internal - accesible from the same Assembly or Derived class
BASE class constructors Always executed first (NOT inherited...need to ReDefine)
Upcasting (derived-class to BASE class)
Downcasting (BASE to derived)
Allows one class to contain another (Car has an Engine)
looser coupling than Inheritance (Tightly Coupled application = BAD)
Any Inheritance can be built to Composition instead
stored in JSON config-file
dotnet user-secrets set ''
stored in AppData/Microsoft/UserSecrets
Right-click project "Manage User Secrets"
For Console Apps
in .csproj:
Run computation-intensive code on a different thread than the U.I. thread
Context Switching
Thread thread = new Thread(spawning thread)
main Thread always has the U.I.
Debug -> Windows -> Threads (Name your threads for debugging...thread.Name = " " )
Multi Threading
Managed by the Thread-Scheduler
CLR delegates it
Operating system takes care of it
Separate-copy of local-variables is created on each thread's memory-stack
static variable shared amongst threads
new Thread("methodName").Start()
when writing code with shared-resources have to think about Locking-Strategy
thread.Start();
thread.Join();
will wait for thread to finish
any subsequent thread will wait for it to finish
only way to share a value between threads is using thread.Join()
Tasks
Can-be chained
may use thread pool
Good for I/O bound operations
Task.Result() (will block program until finished)
Continuation
Async-task that is invoked by another task called an antecedent
Pass data from antecedent to the continuation-task
Control how continuation is invoked
Able to cancel continuation
Multiple continuations from one antecedent
Exclusive-Lock (1 thread to access certain section of code)
Lock
Mutex
Non-Exclusive-locks
Semaphore
SemaphoreSlim
Semaphores are resource intensive
Limit amount of concurrent threads that can access a resource
Reader/Writer
Allow multiple-threads to access a resource
Incrementing a class Automatically
fine in single-threaded environment
Race-conditions can happen
static int _refid
public REFID {get; set; }
Interlocked.Increment(ref refid)
undefined and null coerce to each other when compared with ==
A monolithic architecture means that your app is written as one cohesive unit of code whose components are designed to work together, sharing the same memory space and resources.
A microservice architecture means that your app is made up of lots of smaller, independent applications capable of running in their own memory space and scaling independently from each other across potentially many separate machines.
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.