.Net Core Flashcards
What is .net core?
A open source framework used to build applications from web applications, native applications etc. Most frequently coded using C# language which is an object orientated language that encompasses many modern programming disciplines.
static typing > compiler can do checks on types at compile type rather than run time.
Describe the middleware vs filters in a .net core web application?
Middleware operates on on every request / response. e.g Authentication or Localization middleware
MVC middleware > Filters operate at the MVC layer, authorization, action filter and have access to access routing / MVC context
How does routing work in .net core?
Conventional routing - useEndpoints - Controller/Action/id
Attribute routing - defined in the attribute
Authentication and authorization .net core
.NetCore use middleware for authentication which can be setup on startup.
Configure services add authentication such as JWT authentication, validate authority and other token parameters.
Configure method used for http requests useAuthentication
Authorization allows you to set Policies. I have used that for specific roles or they have given context.
Takes a Policy Name, define requirement, generally used a role requirement in terms of what roles are allowed etc. AuthorizationHandler then defined to handle the requirement and registers on startup. We can then access the handler context for the user ClaimsPrincipal. Essential access the custom claim to access json object with roles.
On controller / action we can define an Authorization Attribute
context.Succeed
Complete Task
What is Threading?
An analogy usually helps. You are cooking in a restaurant. An order comes in for eggs and toast.
Synchronous: you cook the eggs, then you cook the toast.
Asynchronous, single threaded: you start the eggs cooking and set a timer. You start the toast cooking, and set a timer. While they are both cooking, you clean the kitchen. When the timers go off you take the eggs off the heat and the toast out of the toaster and serve them.
Asynchronous, multithreaded: you hire two more cooks, one to cook eggs and one to cook toast. Now you have the problem of coordinating the cooks so that they do not conflict with each other in the kitchen when sharing resources. And you have to pay them.
What is async await?
Async await is the mechanism to manage long running operations / I/O or DB calls with indeterminate timeframe. The advantage of this is that it enables the state machine which allows the current thread to be freed up in order to perform another Task (single operation). This enables and supports vertical scaling in terms of maximising the resources in a given server.
What testing tools have you used in .net core?
In terms of testing frameworks I have used both nunit and mstest. In terms of mocking I have used nsubstitute and moq. AutoMoq for setting up test objects.
What is TDD?
TDD stands for Test Driven Development is the software development process relying on software requirements converted into test cases before the software is fully developed. The trigger for a new test is a requirement not a new class or method.
It focuses on writing basic test to meet the requirement that might not compile
The write the code as quickly as possible to meet the requirement
Refactor the code for readability, duplication, code smells, design patterns
You should not have to write new tests
Don’t blindly follow process for process sake. Use your experience and keep and open mind about what’s important to your products needs. __ Elliot Chance
Mocks are useful when a resource is expensive to create, people have used them to isolate classes
What is BDD?
BDD (Behaviour-driven development) Testing is a technique of agile software development and is as an extension of TDD, i.e., Test Driven Development. In BDD, test cases are written in a natural language that even non-programmers can read. Involves product, stakeholders developers writing test cases to meet the need.
Gherkin given when then
Specflow
Playwright
What is DI?
Dependency Inversion Principle (suggests a solution)
High level modules dont depend on lower level modules both depend on abstractions
Abstraction dont depend on details, details depend on abstractions
Maintainable, loose couple, testable code
IOC - is the mechanism to apply the principle that allows higher level modules to depend on abstraction rather than concrete implementations of lower level modules
Dependency Injection - design pattern to implement IOC allows you to inject low level component into your high level component
Register it, resolution at runtime and disposition lifetime
IServiceProvider > IServiceCollection
What are using blocks?
used to outline the scope of unmanaged resource to ensure its memory is freed up as soon as possible. Generally used with the IDisposable interface in order to outline how it should be disposed.
Abstract class vs 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.
extends is for extending a class.
implements is for implementing an interface
A big impediment to software evolution has been the fact that you couldn’t add new members to a public interface. You would break existing implementers of the interface; after all they would have no implementation for the new member!
What is differed execution?
Deferred execution means that the evaluation of an expression is delayed until its realized value is actually required. It greatly improves performance by avoiding unnecessary execution.
It is executed when the query object is iterated over a loop.
IQueryable queries out-of-memory data stores, while IEnumerable queries in-memory data
Constant vs readonly
A const is a compile-time constant whereas readonly allows a value to be calculated at run-time and set in the constructor or field initializer. So, a ‘const’ is always constant but ‘readonly’ is read-only once it is assigned.
Virtual / abstract / Override
Abstract Method Abstract Method resides in abstract class and it has no body. Abstract Method must be overridden in non-abstract child class.
Virtual Method
Virtual Method can reside in abstract and non-abstract class.
It is not necessary to override virtual method in derived but it can be.
Virtual method must have body ….can be overridden by “override keyword”…..