SQL:
Get Highest salary of 3 employee without using limit,and top
SELECT StageID, DepartmentNumber, UserEmail
,DENSE_RANK() OVER (PARTITION BY DepartmentNumber
ORDER BY UserEmail ASC) AS DRANK
FROM mytable Get full name from First name and last name of table
create view
SELECT CONCAT (FirstName, ' , ' , LastName) AS fullname (salary*12)+(experience*500) AS total FROM staff
What is .NET Core, and how does it differ from the .NET Framework?
.NET Core (now simply .NET 5, 6, 7+) is a free, open-source, cross-platform framework for building modern applications that can run on Windows, macOS, and Linux.
The main differences are:
• Cross-Platform: The .NET Framework is Windows-only, while .NET Core is cross-platform.
• Deployment: .NET Core applications can be deployed as self-contained executables that include all dependencies, whereas .NET Framework apps require the framework to be installed on the target machine.
• Modularity & Performance: .NET Core has a modular design and is optimized for performance and microservices architecture, making it suitable for cloud-native applications.
2. Explain the different service lifetimes in ASP.NET Core Dependency Injection (DI).
Services in ASP.NET Core can be registered with three different lifetimes in the Startup.cs (or Program.cs in newer versions) file:
• Transient: A new instance of the service is created every time it is requested from the service container. This is ideal for lightweight, stateless services.
• Scoped: An instance is created once per client request (connection) and is reused within that same request scope. It is disposed at the end of the request.
• Singleton: A single instance is created the first time it is requested and that same instance is used by all subsequent requests throughout the application's lifetime.
3. What is middleware in ASP.NET Core, and how does it work?
Middleware components are software parts assembled into an application pipeline to handle HTTP requests and responses. Each component can choose to pass the request to the next component in the pipeline, perform logic before or after the next component, or "short-circuit" the pipeline entirely (e.g., in the case of an error or serving a static file). They are configured in the Configure method of the Startup class or directly in Program.cs.
Architecture and Design Patterns
4. How do you implement Dependency Injection (DI) in a .NET Core application?
.NET Core has built-in support for DI. Services are registered in the ConfigureServices method of the Startup.cs file (or directly in the Program.cs using the IServiceCollection methods like AddSingleton, AddScoped, or AddTransient). The container then automatically injects these dependencies via the class constructor.
5. Explain the role of Program.cs and Startup.cs files in a .NET Core project.
• Program.cs: This is the entry point of the application, containing the Main method. It is responsible for creating and configuring the application host (which manages application lifetime, server configuration, logging, and DI).
• Startup.cs: This class (used in older versions, or implicitly configured in modern Program.cs via WebApplication.CreateBuilder) is where you configure the application's services (in ConfigureServices) and the HTTP request pipeline (in Configure using middleware).
6. What is the CQRS (Command Query Responsibility Segregation) pattern, and how might you implement it in .NET Core?
CQRS is an architectural pattern that separates the operations for reading data (Queries) from those for updating data (Commands).
• Implementation: In a .NET Core application, this often involves using different data models and potentially different databases for reads and writes. Libraries like MediatR are commonly used to route commands and queries to their respective handlers, promoting clear separation of concerns and scalability in complex, high-traffic applications.
7. How do you handle transient faults (e.g., network glitches, temporary database unavailability) in .NET Core applications?
The Polly library is a popular choice for implementing resilience and transient fault handling in .NET Core. Polly allows you to define policies such as Retry, Circuit Breaker, and Timeout to handle temporary failures gracefully. These policies can be integrated with HttpClient for robust API calls.
Advanced Topics
8. Explain the difference between synchronous and asynchronous programming in .NET Core, and when to use each.
• Synchronous: Code execution proceeds one line at a time. A process will block the main thread until it completes.
• Asynchronous: Uses keywords like async and await to perform operations (especially I/O-bound tasks like database calls or web service requests) without blocking the main thread, allowing the application to handle other requests simultaneously.
• When to use: Use synchronous programming for simple, CPU-bound operations. Use asynchronous programming for I/O-bound tasks in web applications to improve responsiveness, performance, and scalability by maximizing thread utilization.
9. What are the benefits of using Entity Framework Core (EF Core) for data access?
EF Core is a lightweight, cross-platform Object-Relational Mapper (ORM).
• Benefits:
• Allows developers to interact with the database using .NET objects, eliminating most manual SQL queries.
• Supports LINQ (Language Integrated Query) for data querying.
• Provides built-in features like change tracking, migrations, and support for in-memory databases for testing.
• Promotes a clean, object-oriented approach to data access.
10. How do you secure Web APIs in ASP.NET Core using JWT (JSON Web Tokens)?
JWT authentication involves several steps:
1. Configuration: Configure JWT middleware in the Startup.cs file, specifying token validation parameters (issuer, audience, signing key).
2. Login/Token Generation: When a user logs in, the application generates a JWT containing claims (user information) and signs it with a secret key.
3. Client Usage: The client stores the token (e.g., in local storage) and sends it in the Authorization header of subsequent requests.
4. Validation: The server-side middleware validates the token's signature and claims before allowing access to protected endpoints, often marked with the [Authorize] attribute.
𝐌𝐚𝐬𝐭𝐞𝐫𝐢𝐧𝐠 .𝐍𝐄𝐓 𝐂𝐨𝐫𝐞: 20 𝐟𝐫𝐨𝐦 𝐄𝐚𝐬𝐲 𝐭𝐨 𝐇𝐚𝐫𝐝
What is .NET Core, and how does it differ from .NET Framework?
What is the role of the Startup.cs file in an ASP.NET Core application?
What are middleware components, and how do they work in the ASP.NET Core request pipeline?
Middleware is software that's assembled into an app pipeline to handle requests and responses. Each component:Chooses whether to pass the request to the next component in the pipeline.Can perform work before and after the next component in the pipeline.
How do you configure dependency injection in .NET Core?
What is the difference between IConfiguration and IOptions in .NET Core?
How does the appsettings.json file work in .NET Core?
What is the significance of the Program.cs file in .NET Core applications?
𝐈𝐧𝐭𝐞𝐫𝐦𝐞𝐝𝐢𝐚𝐭𝐞:
8. What is Kestrel, and why is it used in .NET Core?
9. Explain the concept of routing in ASP.NET Core.
10. What is the purpose of ConfigureServices and Configure methods in the Startup class?
11. How does ASP.NET Core handle cross-origin resource sharing (CORS)?
12. What are the benefits of using Entity Framework Core in .NET Core applications?
13. Explain the role of the IHostedService interface in .NET Core and provide an example of how to implement it.
14. How does ASP.NET Core support asynchronous programming?
𝐀𝐝𝐯𝐚𝐧𝐜𝐞𝐝
15. How does the ASP.NET Core request processing pipeline work internally?
16. How would you design and implement a microservices architecture using ASP.NET Core?
17. What is the difference between IApplicationBuilder and IServiceCollection in .NET Core?
18. How can you implement centralized logging and monitoring in a .NET Core application?
19. Explain the difference between transient, scoped, and singleton lifetimes in dependency injection.
20. How would you implement health checks in an ASP.NET Core application?
21. What is the purpose of the BackgroundService class, and how does it relate to IHostedService?
22. How does the .NET Core Generic Host differ from the Web Host?
23. How would you handle global exception handling in ASP.NET Core?
24. What is the purpose of DataProtection in .NET Core, and how would you use it?
25. How can you configure and manage multiple environments in ASP.NET Core?
JWT Token:
https://medium.com/@sajadshafi/jwt-authentication-in-c-net-core-7-web-api-b825b3aee11d
LinQ:
No comments:
Post a Comment