NisanurBulut / Shilla

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ο»Ώ

Magic Shilla App πŸ“Œ

❀ I have missed the code Net core

Give a Star! ⭐

If you like or are using this project to learn or start your solution, please give it a star. Thanks!



Technical Dictionary

🧨 Binding Parameters in Asp.Net MVC

  1. FromQuery :

    This type contains query items. To use them, we need to read parameters from URL address and we need to check ? character. Example https://example.com/api/products?id=123&name=keyboard

    [HttpGet("products")]
    public IActionResult GetProduct([FromQuery] int id, [FromQuery] string name)
    {
    
    }

  2. FromBody :

    This type uses data inside of HTTP Body. it generally used for POST, PUT or PATCH requests. Kind of data might be JSON, XML or another type.

    [HttpPost("products")]
    public IActionResult CreateProduct([FromBody] ProductDto productDto)
    {
       
    }
  3. FromRoute :

    It is used to bind routing parameters in the URL to a parameter in the API method. Redirect parameters are dynamic values specified in a specific part of the URL. Example https://example.com/api/products/{id} It is commonly used when reading resource id information.

    [HttpGet("products/{id}")]
    public IActionResult GetProductById([FromRoute] int id)
    {
    }

🧨 Validation

Validation Diagram

🧨 Region Directive

I am particularly fond of 😻 the #region directive. It allows us to collapse code in a customized manor. Regions are created in this format,

#region NisanurStartedCoding
return Ok(πŸ‘Œ);
#endregion

Benefits of using region director :

  • Well organized
  • easily readable
  • code can be easily navigated
  • increade efficiency

Dapper vs Entity FrameWork

Dapper v/s Entity Framework(Core) https://www.youtube.com/watch?v=ialFGpKD8yI

IEnumerable vs IQueryable

Dapper v/s Entity FrameWork


🧨 Differences Between Scoped, Transient, And Singleton Service

Why we require

  • It defines the lifetime of object creation or a registration in the .net core with the help of Dependency Injection.
  • The DI Container has to decide whether to return a new object of the service or consume an existing instance.
  • The lifetime of the Service depends on how we instantiate the dependency.
  • We define the lifetime when we register the service.

Three types of lifetime and registration options

  1. Scoped
  2. Transient
  3. Singleton

Scoped

  • In this service, with every HTTP request, we get a new instance.
  • The same instance is provided for the entire scope of that request.
    • eg., if we have a couple of parameter in the controller, both object contains the same instance across the request
  • This is a better option when you want to maintain a state within a request.
services.AddScoped<IAuthService,AuthService>();

Transient

  • A new service instance is created for each object in the HTTP request.
  • This is a good approach for the multithreading approach because both objects are independent of one another.
  • The instance is created every time they will use more memory and resources and can have a negative impact on performance
  • Utilize for the lightweight service with little or no state.
services.AddTransient<ICronJobService,CronJobService>();

Singleton

  • Only one service instance was created throughout the lifetime.
  • Reused the same instance in future, wherever the service is required
  • Since it's a single lifetime service creation, memory leaks in these services will build up over time.
  • Also, it has memory efficient as they are created once reused everywhere.
services.AddSingleton<ILoggingService, LoggingService>();

When to use which Service

Singleton approach => We can use this for logging service, feature flag(to on and off module while deployment), and email service

Scoped approach => This is a better option when you want to maintain a state within a request.

Transient approach =>  Use this approach for the lightweight service with little or no state.


πŸ” AsNoTracking:

in scenarios where you only need read-only access to data and don't intend to modify or update it, using AsNoTracking can offer performance benefits.

πŸ’‘ It avoids the overhead of change tracking, resulting in faster query execution.

πŸ” AsNoTrackingWithIdentity:

When using AsNoTrackingWithIdentity, EF Core still tracks the identity of entities retrieved from the database.

πŸ’‘ It is particularly useful when working with scenarios that require a mix of read-only and update operations

πŸ“Œ Key Differences:

  • AsNoTracking completely disables change tracking, resulting in improved performance for read-only scenarios
  • AsNoTrackingWithIdentity disables change tracking for most properties, but it keeps track of the entity's identity, allowing updates to be applied efficiently when necessary.
πŸ”§ When to Use Which ❓ when should you use each method ❓
  • Use AsNoTracking when you only require read-only access to entities and want to optimize performance.
  • Use AsNoTrackingWithIdentity when you need both read-only access and the ability to update specific entities efficiently.

Data Transfer Objects are used to transfer data between the Application Layer and the Presentation Layer.


πŸ’‘ Layouts

Layout actually used to maintain consistency in the web pages and also using this, repetitive code can be reduced. Normally, layout mainly contains header, navigation, menu elements or footer sections.

πŸ’‘ Partial Views

Partial views mainly reduce code duplicate by maintain reusable parts of the views.

πŸ’‘ View Components

It is quite similar to the partial view in terms of reusability and reduce code repetition.

  • View components do not use model binding
  • View Component class must be derived from the ViewComponent class.
  • Like Partial View, View components does not depend on controllers. It has its own class to implement the logic to develop the component’s model and razor markup view page.
  • View Components can utilize dependency injection
Actually, views help us to establish a SOC Design (Separation of Concerns) within the MVC application. It basically separates the user interface from other parts of the application.

Packages Links References
  1. Microsoft.AspNetCore.JsonPatch

  2. Microsoft.AspNetCore.Mvc.NewtonsoftJson

  3. Serilog.AspNetCore

  4. Serilog.Sinks.File

  5. Microsoft.EntityFrameworkCore.SqlServer

  6. Microsoft.EntityFrameworkCore.Tools

  7. AutoMapper.Extensions.Microsoft.DependencyInjection

  8. AutoMapper

  9. Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer/5.1.0

  10. Microsoft.AspNetCore.Identity.EntityFrameworkCore

  1. What is JSON Patch?

  2. Generate Fake C# Data

  3. 10-bad-practices-to-avoid-in-aspnet-core-api-controllers

  1. differences-between-scoped-transient-and-singleton-service

  2. explaining-difference-between-asnotracking-net-core

  3. Data-Transfer-Objects

  4. Dapper v/s Entity Framework(Core)

  5. IEnumerable vs IQueryable

  6. Udemy Course RESTful Web API - The Complete Guide (.NET7 API) Part 1


Architecture Patterns Speed Up API Performance Methods

Swagger Documentation

swagger_documentation

About


Languages

Language:HTML 93.5%Language:C# 4.1%Language:SCSS 1.4%Language:JavaScript 0.9%Language:CSS 0.0%