Task: Implement a Custom Middleware for Request Logging and Performance Monitoring
Objective: Develop a custom middleware in ASP.NET Core that logs incoming HTTP
requests and measures the time taken to process each request. The middleware should
log the following details:
HTTP method (e.g., GET, POST)
Request path
Query parameters
Response status code
Processing time in milliseconds
Requirements:
Middleware Implementation:
Create a class named RequestLoggingMiddleware that handles the logging
logic.
Implement the InvokeAsync method to capture request and response details.
Performance Measurement:
Record the time taken to process each request using a high-resolution
timer.
Logging:
Use ASP.NET Core's built-in logging framework (ILogger) to log the
information.
Ensure that logs are written in a structured format for easy analysis.
Registration:
Configure the middleware in the ASP.NET Core request pipeline within the
Startup class.
Considerations:
Thread Safety: Ensure that the middleware handles concurrent requests
appropriately.
Error Handling: Log exceptions without disrupting the request pipeline.
Performance Impact: Minimize the overhead introduced by the logging mechanism.
======================
1. Implement a Thread-Safe Singleton Pattern
Task: Design a singleton class in C# that ensures thread safety without using
language-level constructs like lock. The implementation should be lazy-initialized
and performant.
Requirements:
Ensure that only one instance of the class is created, even in a multithreaded
environment.
Avoid using explicit locking mechanisms.
Demonstrate the usage of the singleton instance in a multithreaded scenario.
Purpose: This exercise evaluates the candidate's understanding of design patterns,
thread safety, and efficient resource management in .NET.
=====================
Develop a Custom LINQ Extension Method
Task: Create a LINQ extension method named Batch that processes a collection in
batches of a specified size. The method should yield each batch as an
IEnumerable<T>.
Requirements:
The method should be an extension of IEnumerable<T>.
It should accept an integer parameter batchSize indicating the number of items
per batch.
Implement the method using yield return to facilitate deferred execution.
Example usage
var numbers = Enumerable.Range(1, 10);
var batches = numbers.Batch(3);
foreach (var batch in batches)
{
Console.WriteLine(string.Join(", ", batch));
}
========================
String Operations
Create a function to receive a string from console and then remove duplicate
characters from the string and reprint the unique string
Eg. tessst -> test
Create a function which receives two strings and find if they are anagrams
Create a function which receives a string and return if it is a palindrome or not