asp.net core learn

.NET Core WebApi

RESTful specification

  • RESTful API best practices< /li>
  • Understand the RESTful architecture

Interface version control

  • Support multiple versions of ASP.NET Core Web API
  • ASP.NET Core API version control
  • Configuration usage process
    • Usage method
      • Add services.AddApiVersioning() to the ConfigureServices method of the Startup class< /li>
      • App.UseApiVersioning() is added to the Configure method of the Startup class.
      • ApiVersion(“1.0”) is added to the application on the controller or interface.
    • Access form
      • Access is realized by query string, the specific format: api/values?api-version=1.0
      • Access is achieved by rewriting the interface routing method. The routing is modified to: [Route(“api/v{version:apiVersion}/[controller]”)]; specific format: api/v1/ values
      • Access is achieved through the header specified field.

Swagger

  • .NetCore WebApi —— Swagger version Control
  • .NetCore WebApi——Swagger simple configuration

cross-domain strategy

Dependency injection

  • ASP.NET Core dependency injection uses its own IOC container
  • ASP.NET Core uses Autofac to implement IOC injection
  • ASP.NET Core uses Autofac to implement AOP interception

database

  • MySQL InnoDB lock mechanism comprehensive analysis and sharing
transaction characteristics
  • Persistence: Once the transaction is committed, the data will be written to the database and stored persistently.
  • Atomicity: Each transaction may be composed of multiple operations, but the transaction itself is regarded as the smallest unit of operation. It is impossible for operations in a transaction to have both success and failure states at the same time, or all are successful , Otherwise restore to the state before the transaction was executed.
    • The initial state of the Active transaction, which means it is being executed.
    • Partially Commited is partially executed, or after the last statement is executed.
    • Failed After the operation is found to be abnormal and the transaction cannot be continued.
    • Commited successfully executed the entire transaction.
    • The Aborted transaction is rolled back and the database is restored to its pre-execution state.
  • Consistency: Before and after the transaction is executed, the data meets the data integrity constraints. The integrity constraints may include primary key constraints, foreign key constraints, and user-defined constraints. The integrity constraints may not be satisfied during the execution of the internal operations of the transaction, but the consistency emphasizes whether the transaction is satisfied before and after the execution, ignoring the intermediate process.
  • Isolation: Modifications made by one firm are invisible to other transactions.
Transaction Isolation Level
  • Read uncommittedREAD UNCOMMITTED Even if the data changes in the transaction are not committed Visible to other affairs.
    • Dirty reading
    • Not repeatable reading
    • Phantom reading
    • Update lost
  • Read CommittedREAD COMMITTED The data changes in the transaction have been committed and are visible to other transactions.
    • Not repeatable read
    • Phantom read
    • Update lost
  • Repeatable readREPEATABLE READ The data change in the transaction has been committed and is not visible to the ongoing transaction.
    • Phantom read
    • Update lost
  • Serialization SERIALIZABLE forces all transactions to be executed serially.
    The difference between read committed and repeatable read: whether the transaction being executed can see the data changes submitted by other transactions, the read submitted is visible, and the repeatable read is invisible.
    SqlServer default transaction isolation level is read submitted; MySql default transaction isolation level is repeatable read.
Isolation features cause problems
  • Dirty read: read data that has been modified and uncommitted by other transactions in the current transaction , Violation of isolation.
  • Unrepeatable read: Read in the current transaction that other transactions have modified and submitted data, which violates consistency.
  • Phantom read: Data insertion causes inconsistent results of read queries in a transaction.
    • MVCC
    • Next-Key Lock
  • Update is lost: Concurrent transaction updates the same record, and one modification overwrites it after it appears The previous modification situation.
    • MVCC
    • Record Lock

lock mechanism

Two-stage lock protocol (2PL)
  • Before reading or writing any data, you must first apply for and obtain a blockade of the data.
  • After releasing a blockade, the transaction no longer applies for and obtains any other blockades.
pessimistic locking mechanism

Get the lock first and then visit

  • Share Locks (Share Locks, S locks): After a thread adds a shared lock to the data, other threads can only read the data and cannot modify it.
  • Exclusive Locks (eXclusive Locks, X locks): After a thread adds an exclusive lock to the data, other threads cannot read or modify it.
  • Intent Locks: When acquiring a lock on a specified resource, first acquire an intent lock on the previous hierarchical structure. The main function is: when you need to acquire a table lock or page lock, you only need to judge whether there is a table intention lock or a page intention lock to quickly.
    The compatibility rule is: shared locks and shared locks are compatible, exclusive locks and other locks are excluded.
Optimistic locking mechanism
  • Assuming that multiple concurrent transactions will not affect each other, each transaction can be locked without locking Deal with the part of the data affected by each.
  • Before submitting the data update, each transaction will first check whether the data has been modified by other transactions after the transaction reads the data. If other transactions are updated, the transaction that is being committed will be rolled back.

Index

Clustered index and non-clustered index (also called secondary index)

Index classification
  • Storage structure distinction
    • Clustered index
    • Non-clustered index
  • Data uniqueness distinction
    • Unique index
    • Primary key index

Encoding format And type

what is the difference between char, varchar, text, nchar, nvarchar, ntext?
  • char(n): fixed length; high index efficiency; n must be a value between 1 and 8,000, and the storage size is n bytes .
  • varchar(n): variable length; indexing efficiency is lower than char(n), flexible; n must be a value between 1 and 8,000, and the storage size is The actual length of the bytes of the input data. The actual length of the varchar type is the actual length of its value + 1. Why “+1”? This one byte is used to store the actual length used.
  • text(n): variable length; non-Unicode data; no need to specify length. The maximum length is 2^31-1 (2,147,483,647) characters.
  • nchar(n): fixed length; handling unicode data types; the value of n must be between 1 and 4,000. The storage size is twice n bytes.
  • nvarchar(n): variable length; handling unicode data types; the value of n must be between 1 and 4,000. The storage size of bytes is twice the number of characters entered. The entered data character length can be zero.
  • ntext(n): variable length; processing unicode data type; no need to specify length. Generally speaking, if there are Chinese characters, use nchar/nvarchar, if pure English and numbers, use char/varchar.

Leave a Comment

Your email address will not be published.