1. Suppose we have three middlewares in the pipeline. If an exception occurs in the second middleware, how will the request/response flow behave? Will the third middleware ever get executed?
Answer:
Middleware execution follows a pipeline pattern.
Middleware1 → Middleware2 → Middleware3 → Controller
If Middleware2 throws an exception:
Execution immediately stops.
Middleware3 will not execute.
The exception propagates back through the pipeline.
If an Exception Handling Middleware is configured earlier in the pipeline, it catches the exception and returns an error response.
Example:
app.UseExceptionHandler("/Error");
app.UseMiddleware<Middleware1>();
app.UseMiddleware<Middleware2>();
app.UseMiddleware<Middleware3>();
Interview Answer:
If Middleware2 throws an exception and does not handle it, Middleware3 will never execute. The exception travels back up the pipeline and can be handled by a global exception middleware configured earlier in the request pipeline.
2. An API is consumed by two customers: one expects JSON and another expects XML. How can we support both without creating separate endpoints?
Answer:
Use Content Negotiation.
Configure both formatters:
builder.Services.AddControllers()
.AddXmlSerializerFormatters();
Client Requests:
Accept: application/json
Returns JSON.
Accept: application/xml
Returns XML.
Controller:
[HttpGet]
public IActionResult GetEmployee()
{
return Ok(employee);
}
Interview Answer:
ASP.NET Core supports content negotiation. Based on the Accept header, the same endpoint can return JSON or XML without creating multiple APIs.
3. Middleware order matters — why? What happens if arranged incorrectly?
Answer:
Middleware executes in the order registered.
Correct Order:
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
Wrong Order:
app.UseAuthorization();
app.UseAuthentication();
Problem:
Authorization executes before user identity is established.
User becomes unauthorized.
Other examples:
CORS after endpoints → CORS fails.
Exception middleware at bottom → Exceptions not captured.
Static files after routing → Files may not be served.
Interview Answer:
Middleware order is critical because each middleware depends on work done by previous middleware. Incorrect ordering can cause authentication failures, routing issues, CORS problems, and unhandled exceptions.
Angular Scenario-Based Questions & Answers
1. If a component is declared in two different NgModules, what happens?
Answer:
Angular throws a compilation error.
Example:
@NgModule({
declarations: [EmployeeComponent]
})
export class ModuleA {}
@NgModule({
declarations: [EmployeeComponent]
})
export class ModuleB {}
Error:
Type EmployeeComponent is part of the declarations of 2 modules.
Solution:
Declare the component in only one module and export it.
@NgModule({
declarations: [EmployeeComponent],
exports: [EmployeeComponent]
})
export class SharedModule {}
Interview Answer:
Angular does not allow a component to be declared in multiple modules. The application fails to compile with a duplicate declaration error.
2. Service A depends on Service B, and Service B depends on Service A. What happens?
Answer:
This creates a circular dependency.
Example:
@Injectable()
export class ServiceA {
constructor(private serviceB: ServiceB) {}
}
@Injectable()
export class ServiceB {
constructor(private serviceA: ServiceA) {}
}
Angular DI Error:
Circular dependency detected
Solutions:
Refactor responsibilities.
Introduce a third service.
Use an event-based pattern (RxJS Subject).
Interview Answer:
Angular's dependency injection container detects circular dependencies and throws an error because it cannot determine which service should be instantiated first.
SQL Scenario-Based Questions & Answers
1. A column contains values 1, 2, 3 and NULL. How does ORDER BY treat NULL values?
Assume:
Value
-----
1
2
3
NULL
ORDER BY ASC
SELECT Value
FROM TestTable
ORDER BY Value ASC;
Result in SQL Server:
NULL
1
2
3
ORDER BY DESC
SELECT Value
FROM TestTable
ORDER BY Value DESC;
Result:
3
2
1
NULL
SQL Server Rule:
NULL is treated as the lowest value.
Interview Answer:
In SQL Server, NULLs appear first in ascending order and last in descending order because NULL is considered lower than any numeric value.
2. What happens if we try to insert values directly into an Identity column?
Table:
CREATE TABLE Employee
(
Id INT IDENTITY(1,1),
Name VARCHAR(50)
)
Query:
INSERT INTO Employee(Id, Name)
VALUES (100, 'John');
Error:
Cannot insert explicit value for identity column
when IDENTITY_INSERT is set to OFF.
To Insert Explicitly
SET IDENTITY_INSERT Employee ON;
INSERT INTO Employee(Id, Name)
VALUES (100, 'John');
SET IDENTITY_INSERT Employee OFF;
Important Notes
Only one table per session can have
IDENTITY_INSERT ON.Generally used during data migration.
Interview Answer:
SQL Server does not allow manual insertion into an Identity column by default. To insert explicit values, IDENTITY_INSERT must be enabled temporarily.
Additional Follow-up Interview Questions
.NET
Difference between
Use,Run, andMapmiddleware?What happens if
next()is not called in middleware?How does global exception handling work in ASP.NET Core?
Angular
Difference between lazy loading and eager loading?
What is OnPush change detection?
Difference between Subject, BehaviorSubject, and ReplaySubject?
SQL
Difference between DELETE, TRUNCATE, and DROP?
Clustered vs Non-Clustered Index?
ROW_NUMBER(), RANK(), and DENSE_RANK() differences?
These are commonly asked in Senior .NET + Angular + SQL interviews (8–12+ years experience).
No comments:
Post a Comment