Interview Q&A

Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.

4616 total questions 4516 technical 100 career & HR 4346 from PDF library

Showing 26–50 of 103

Popular tracks

Mid PDF
What are the benefits of Unit of Work in managing transactions?

Transactional consistency: All changes across repositories are saved in a single transaction. Centralized commit: All changes are committed through one method (Complete()), improving control and readability. Reduced code…

SOLID Read answer
Mid PDF
Can you combine Unit of Work with Dependency Injection?

Yes, combining Unit of Work with Dependency Injection (DI) is a best practice in modern .NET applications. DI allows the Unit of Work to be injected into services or controllers, managing its lifecycle effectively. This…

SOLID Read answer
Junior PDF
What is Dependency Injection and why is it useful?

Dependency Injection (DI) is a design pattern that allows an object to receive its dependencies from an external source rather than creating them itself. This promotes loose coupling, enhances testability, and simplifies…

SOLID Read answer
Mid PDF
How does .NET Core support Dependency Injection out of the box?

.NET Core has a built-in DI container that's tightly integrated into the framework. When you create a new ASP.NET Core project, DI is configured automatically and used in controllers, middleware, services, etc. You regis…

SOLID Read answer
Mid PDF
How do you register services for DI in ASP.NET Core?

Services are registered in the Program.cs or Startup.cs file using the IServiceCollection interface. Example: builder.Services.AddTransient<IProductService, ProductService>(); builder.Services.AddScoped<IOrderSe…

SOLID Read answer
Junior PDF
What is the difference between Scoped, Singleton, and Transient lifetimes?

Transient: A new instance is created every time it is requested. Scoped: A single instance is created per request/HTTP request. Singleton: A single instance is created and shared across the application lifetime. Lifetime…

SOLID Read answer
Mid PDF
How do you handle circular dependencies in DI?

Circular dependencies occur when two or more services depend on each other, creating an infinite loop. To handle them: Refactor the code to remove tight coupling. Use interfaces or events to break the cycle. Consider usi…

SOLID Read answer
Mid PDF
What are the advantages of using DI in unit testing?

Easier mocking of dependencies using frameworks like Moq or NSubstitute. No need to instantiate real implementations (e.g., database access) for tests. Improved isolation of the unit under test. Faster, more reliable tes…

SOLID Read answer
Mid PDF
Can DI be used without a DI container? How?

Yes, DI can be implemented manually without using a DI container. You simply pass dependencies through constructors or methods: public class OrderService { private readonly IOrderRepository _repo; public OrderService(IOr…

SOLID Read answer
Mid PDF
What are common pitfalls when implementing DI?

Over-injection (too many dependencies in one class – violates SRP) Service locator anti-pattern Incorrect lifetimes, leading to memory leaks or unintended reuse Tight coupling to the DI container (e.g., using container A…

SOLID Read answer
Mid PDF
How does DI relate to Inversion of Control (IoC)?

Inversion of Control (IoC) is a broader principle where control over object creation and dependency resolution is transferred from the class itself to an external framework or container. Dependency Injection is a specifi…

SOLID Read answer
Junior PDF
What is the Single Responsibility Principle?

The Single Responsibility Principle (SRP) states that a class should have only one reason to change. In other words, it should have only one responsibility or job. Each class should do one thing, and do it well. For exam…

SOLID Read answer
Mid PDF
How can you identify violations of SRP in code?

You can identify SRP violations by asking questions like: Does this class perform more than one function (e.g., data access and business logic)? Does it change for different reasons (e.g., changes in UI and database)? Do…

SOLID Read answer
Mid PDF
Can you give an example of refactoring code to follow SRP?

Before (SRP Violation): public class Invoice { public void GenerateInvoice() { /* logic */ } public void SaveToDatabase() { /* logic */ } public void SendEmail() { /* logic */ } } This class has 3 responsibilities: gener…

SOLID Read answer
Mid PDF
How does SRP improve maintainability?

SRP improves maintainability by: Reducing complexity – Classes are smaller and easier to understand. Easier testing – Each class can be tested in isolation. Better separation of concerns – Business logic, data access, an…

SOLID Read answer
Mid PDF
What happens if a class has multiple responsibilities?

If a class has multiple responsibilities: It becomes tightly coupled and harder to change without affecting other parts. Changes are more error-prone and often introduce bugs. Testing becomes harder since the class relie…

SOLID Read answer
Mid PDF
What does the Open/Closed Principle mean?

The Open/Closed Principle (OCP) states that: Software entities (classes, modules, functions) should be open for extension but closed for modification. This means you should be able to add new behavior to a class without…

SOLID Read answer
Mid PDF
How can you design classes that are open for extension but closed for modification?

To design classes that follow OCP: Use abstraction (interfaces or abstract classes). Rely on polymorphism and inheritance. Apply composition over inheritance when suitable. Follow design principles like Strategy, Decorat…

SOLID Read answer
Senior PDF
How do design patterns help in adhering to OCP?

Several design patterns are built around the idea of making systems extensible without modifying core logic: Pattern How It Helps With OCP Strategy Allows changing behavior by swapping strategies. Decorator Adds new resp…

SOLID Read answer
Junior PDF
What is an example where OCP is violated?

Before (OCP Violation): public class DiscountCalculator { public decimal CalculateDiscount(string customerType) { if (customerType == "Regular") return 10; if (customerType == "Premium") return 20; if (customerType == "V…

SOLID Read answer
Mid PDF
How does OCP relate to interfaces and abstract classes?

Interfaces and abstract classes provide a contract that other classes can implement or inherit. They enable polymorphism, which allows behavior to be extended without altering existing code. By programming to abstraction…

SOLID Read answer
Junior PDF
What is Liskov Substitution Principle?

The Liskov Substitution Principle (LSP) states that: Subtypes must be substitutable for their base types without altering the correctness of the program. In other words, if class S is a subclass of class T, then objects…

SOLID Read answer
Mid PDF
How can violating LSP cause issues in software design?

Violating LSP can lead to: Unexpected behavior when a subclass does not honor the contract of the base class. Code that breaks at runtime when substituting a derived class. Tightly coupled code that depends on specific i…

SOLID Read answer
Junior PDF
What is an example of violating LSP in .NET code?

Example (Violation of LSP): public class Rectangle { public virtual int Width { get; set; } public virtual int Height { get; set; } public int Area() => Width * Height; } public class Square : Rectangle { public overr…

SOLID Read answer
Mid PDF
How do you ensure subclasses follow LSP?

To ensure subclasses follow LSP: Subclasses should not override behavior in a way that breaks expected behavior. Subclasses should preserve the invariants and preconditions/postconditions of the base class. Avoid overrid…

SOLID Read answer

Design Patterns & SOLID Design Patterns in C# · SOLID

  • Transactional consistency: All changes across repositories are saved in a single

transaction.

  • Centralized commit: All changes are committed through one method

(Complete()), improving control and readability.

  • Reduced code duplication: Prevents repeated save logic across repositories.
  • Improved testability: Enables better unit testing by mocking a single Unit of Work

instead of multiple repositories.

  • Change tracking: Ensures that only modified entities are persisted, reducing

unnecessary database operations.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Yes, combining Unit of Work with Dependency Injection (DI) is a best practice in modern

.NET applications. DI allows the Unit of Work to be injected into services or controllers,

managing its lifecycle effectively. This improves modularity, promotes loose coupling, and

makes the application easier to maintain and test.

Example using constructor injection in a service:

public class OrderService
{
private readonly IUnitOfWork _unitOfWork;
public OrderService(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public void PlaceOrder(Order order)
{

_unitOfWork.Orders.Add(order);

_unitOfWork.Complete();

}
}

Dependency Injection (DI)

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Dependency Injection (DI) is a design pattern that allows an object to receive its

dependencies from an external source rather than creating them itself. This promotes loose

coupling, enhances testability, and simplifies code maintenance.

Benefits:

  • Improves modularity
  • Enables easier unit testing (via mock dependencies)
  • Promotes adherence to SOLID principles (especially the Dependency Inversion

Principle)

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

.NET Core has a built-in DI container that's tightly integrated into the framework. When

you create a new ASP.NET Core project, DI is configured automatically and used in

controllers, middleware, services, etc. You register dependencies in the Program.cs or

Startup.cs file using IServiceCollection.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Services are registered in the Program.cs or Startup.cs file using the

IServiceCollection interface. Example:

builder.Services.AddTransient<IProductService, ProductService>();

builder.Services.AddScoped<IOrderService, OrderService>();

builder.Services.AddSingleton<ILoggingService, LoggingService>();

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

  • Transient: A new instance is created every time it is requested.
  • Scoped: A single instance is created per request/HTTP request.
  • Singleton: A single instance is created and shared across the application lifetime.

Lifetime Created Per Use Case

Transient Every injection Lightweight, stateless services

Scoped HTTP Request Web services handling per-request

data

Singleton App lifetime Logging, configuration, cache

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Circular dependencies occur when two or more services depend on each other, creating an

infinite loop. To handle them:

  • Refactor the code to remove tight coupling.
  • Use interfaces or events to break the cycle.
  • Consider using property injection carefully (not recommended as a first choice).
  • Rethink your design – circular dependencies often indicate architectural issues.
Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

  • Easier mocking of dependencies using frameworks like Moq or NSubstitute.
  • No need to instantiate real implementations (e.g., database access) for tests.
  • Improved isolation of the unit under test.
  • Faster, more reliable tests due to lack of external dependency reliance.
Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Yes, DI can be implemented manually without using a DI container. You simply pass

dependencies through constructors or methods:

public class OrderService
{
private readonly IOrderRepository _repo;
public OrderService(IOrderRepository repo)
{
_repo = repo;
}
}

// Manual injection

var repo = new OrderRepository();
var service = new OrderService(repo);

This is suitable for small or simple applications, though not scalable for large apps.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

  • Over-injection (too many dependencies in one class – violates SRP)
  • Service locator anti-pattern
  • Incorrect lifetimes, leading to memory leaks or unintended reuse
  • Tight coupling to the DI container (e.g., using container APIs in business logic)
  • Circular dependencies due to poor design
  • Registering services in the wrong order or not at all
Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Inversion of Control (IoC) is a broader principle where control over object creation and

dependency resolution is transferred from the class itself to an external framework or

container.

Dependency Injection is a specific implementation of IoC, where the dependencies are

injected into a class rather than the class creating them internally. So, DI is one way to

chieve IoC.

Single Responsibility Principle

(SRP)

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

The Single Responsibility Principle (SRP) states that a class should have only one

reason to change. In other words, it should have only one responsibility or job.

Each class should do one thing, and do it well.

For example, a class that handles user authentication should not also be responsible for

logging or sending emails.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

You can identify SRP violations by asking questions like:

  • Does this class perform more than one function (e.g., data access and business

logic)?

  • Does it change for different reasons (e.g., changes in UI and database)?
  • Does it have too many dependencies or too much code?
  • Are there “and”s in the class name or method descriptions? E.g.,

ReportGeneratorAndPrinter.

Common signs:

  • Long classes or large files
  • Many unrelated methods
  • Hard-to-test code
Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Before (SRP Violation):

public class Invoice
{
public void GenerateInvoice() { /* logic */ }
public void SaveToDatabase() { /* logic */ }
public void SendEmail() { /* logic */ }
}

This class has 3 responsibilities: generating, saving, and emailing.

fter (SRP-compliant):

public class InvoiceGenerator
{
public void Generate() { /* logic */ }
}
public class InvoiceRepository
{
public void Save(Invoice invoice) { /* logic */ }
}
public class EmailService
{
public void Send(Invoice invoice) { /* logic */ }
}

Now each class has a single reason to change.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

SRP improves maintainability by:

  • Reducing complexity – Classes are smaller and easier to understand.
  • Easier testing – Each class can be tested in isolation.
  • Better separation of concerns – Business logic, data access, and infrastructure

code are kept apart.

  • Lower risk of bugs – Changes in one responsibility don’t affect others.

Ultimately, it leads to more modular, flexible, and robust code.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

If a class has multiple responsibilities:
  • It becomes tightly coupled and harder to change without affecting other parts.
  • Changes are more error-prone and often introduce bugs.
  • Testing becomes harder since the class relies on multiple behaviors.
  • Code reusability and readability suffer due to mixed concerns.
  • You violate SRP, which makes code harder to maintain in the long run.

Open/Closed Principle (OCP)

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

The Open/Closed Principle (OCP) states that:

Software entities (classes, modules, functions) should be open for

extension but closed for modification.

This means you should be able to add new behavior to a class without changing its

existing code, which helps avoid breaking existing functionality.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

To design classes that follow OCP:

  • Use abstraction (interfaces or abstract classes).
  • Rely on polymorphism and inheritance.
  • Apply composition over inheritance when suitable.
  • Follow design principles like Strategy, Decorator, or Template Method patterns.

✅ Extend behavior through new classes rather than modifying existing code.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Several design patterns are built around the idea of making systems extensible without

modifying core logic:

Pattern How It Helps With OCP

Strategy Allows changing behavior by swapping strategies.

Decorator Adds new responsibilities dynamically without changing original code.

Template Method Allows subclasses to override certain steps in an algorithm.

Factory Method Makes it easy to introduce new types without altering existing logic.

Observer Extends behavior in reaction to events without altering the source.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Before (OCP Violation):

public class DiscountCalculator
{
public decimal CalculateDiscount(string customerType)
{
if (customerType == "Regular") return 10;
if (customerType == "Premium") return 20;
if (customerType == "VIP") return 30;
return 0;
}
}
If you need to support a new customer type, you must modify this method — violating OCP.

fter (OCP Compliant):

public interface IDiscountStrategy
{

decimal GetDiscount();

}
public class RegularCustomerDiscount : IDiscountStrategy
{
public decimal GetDiscount() => 10;
}
public class PremiumCustomerDiscount : IDiscountStrategy
{
public decimal GetDiscount() => 20;
}
public class VipCustomerDiscount : IDiscountStrategy
{
public decimal GetDiscount() => 30;
}

Now you can add new customer types without modifying existing code — just create a new

strategy.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

  • Interfaces and abstract classes provide a contract that other classes can

implement or inherit.

  • They enable polymorphism, which allows behavior to be extended without altering

existing code.

  • By programming to abstractions (not concrete implementations), you can easily
introduce new behavior (via new implementations) while keeping the core logic

unchanged.

✅ OCP encourages extending via new subclasses or interface implementations, not

modifying existing ones.

Liskov Substitution Principle (LSP)

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

The Liskov Substitution Principle (LSP) states that:

Subtypes must be substitutable for their base types without altering the

correctness of the program.

In other words, if class S is a subclass of class T, then objects of type T should be

replaceable with objects of type S without breaking the application.

This ensures that inheritance models is-a relationships correctly.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Violating LSP can lead to:

  • Unexpected behavior when a subclass does not honor the contract of the base
class.
  • Code that breaks at runtime when substituting a derived class.
  • Tightly coupled code that depends on specific implementations rather than

bstractions.

  • Unit tests failing when testing subclasses in place of base classes.

Essentially, it defeats the purpose of polymorphism.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Example (Violation of LSP):

public class Rectangle
{
public virtual int Width { get; set; }
public virtual int Height { get; set; }
public int Area() => Width * Height;
}
public class Square : Rectangle
{
public override int Width
{
set { base.Width = base.Height = value; }
}
public override int Height
{
set { base.Width = base.Height = value; }
}
}

Now if you substitute Rectangle with Square:

Rectangle rect = new Square();
rect.Width = 5;
rect.Height = 10;

Console.WriteLine(rect.Area()); // Outputs 100, but logically

expected 50

❌ The behavior is incorrect — this is a violation of LSP.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

To ensure subclasses follow LSP:

  • Subclasses should not override behavior in a way that breaks expected behavior.
  • Subclasses should preserve the invariants and preconditions/postconditions of the

base class.

  • Avoid overriding methods to throw exceptions for valid base class behavior.
  • Use composition over inheritance if a subclass doesn’t strictly conform to the base
class behavior.
  • Write unit tests to verify that the subclass behaves identically to the base class in all

valid scenarios.

✅ Ask yourself: Can this subclass be used anywhere the base class is used — without

surprises?

Permalink & share
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details