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 1–25 of 65

Popular tracks

Mid PDF
How do you implement a thread-safe Singleton in .NET?

One common thread-safe implementation uses lazy initialization with Lazy<T>: public sealed class Singleton { private static readonly Lazy<Singleton> instance = new Lazy<Singleton>(() => new Singleton…

SOLID Read answer
Mid PDF
What are the common pitfalls of the Singleton pattern?

Global state: Singleton can lead to hidden dependencies and make testing difficult. Tight coupling: Other classes depend on the Singleton instance, reducing flexibility. Concurrency issues: If not implemented thread-safe…

SOLID Read answer
Mid PDF
Service Locator (anti-pattern) – Dependencies are resolved manually using a?

container, though generally discouraged. What interviewers expect A clear definition tied to SOLID in Design Patterns & SOLID projects Trade-offs (performance, maintainability, security, cost) When you would and woul…

SOLID Read answer
Mid PDF
How does the Singleton pattern affect unit testing?

Singletons can hinder unit testing because they introduce global state, making tests dependent on a shared instance. This can cause tests to be flaky or order-dependent. To mitigate this, use interfaces and dependency in…

SOLID Read answer
Mid PDF
Can you explain the difference between lazy and eager initialization in Singleton?

Eager Initialization: The Singleton instance is created at the time of class loading. It's simple but can waste resources if the instance is never used. Lazy Initialization: The instance is created only when it is first…

SOLID Read answer
Mid PDF
Explain the difference between Factory Method and Abstract Factory patterns.

Factory Method: Defines an interface for creating an object but lets subclasses decide which class to instantiate. It uses inheritance and relies on subclass overriding. Abstract Factory: Provides an interface to create…

SOLID Read answer
Mid PDF
How do you implement a Factory pattern in C#?

A simple example of Factory Method: // Product interface public interface IAnimal { void Speak(); } // Concrete Products public class Dog : IAnimal { public void Speak() => Console.WriteLine("Woof"); } public class Ca…

SOLID Read answer
Mid PDF
What are the advantages of using the Factory pattern?

Encapsulates object creation: Decouples client code from concrete classes. Promotes code reuse: Centralizes object creation logic. Enhances maintainability: Adding new types requires minimal changes to existing code. Sup…

SOLID Read answer
Mid PDF
Can Factory pattern help with Dependency Injection? Provide example.

Yes! Factory pattern can complement Dependency Injection (DI) by abstracting complex object creation logic, especially when the creation involves runtime parameters or complex setup that DI containers can’t handle easily…

SOLID Read answer
Mid PDF
How would you implement Strategy pattern in .NET?

Example: Payment strategy selection // Strategy Interface public interface IPaymentStrategy { void Pay(decimal amount); } // Concrete Strategies public class CreditCardPayment : IPaymentStrategy { public void Pay(decimal…

SOLID Read answer
Mid PDF
What are real-world examples of Strategy pattern usage?

Answer: Payment gateways (Credit Card, PayPal, UPI, etc.) Sorting algorithms (QuickSort, MergeSort, BubbleSort) Authentication strategies (OAuth, JWT, LDAP) Compression algorithms (ZIP, RAR, TAR) Loggers (FileLogger, Con…

SOLID Read answer
Mid PDF
How does the Strategy pattern promote Open/Closed Principle?

It promotes the Open/Closed Principle by allowing you to add new strategies (algorithms or behaviors) without modifying the existing code. The context class uses an interface for the strategy, so new behavior can be adde…

SOLID Read answer
Mid PDF
How does Strategy pattern differ from State pattern?

Aspect Strategy Pattern State Pattern Purpose Encapsulates interchangeable behaviors (algorithms). Encapsulates states and transitions between them. Client Control Client decides which strategy to use. Object changes its…

SOLID Read answer
Mid PDF
How do you implement Repository pattern with Entity Framework?

Here's a basic example: // Entity public class Product { public int Id { get; set; } public string Name { get; set; } } // Generic Repository Interface public interface IRepository<T> where T : class { Task<IEnu…

SOLID Read answer
Mid PDF
What are the benefits of using Repository pattern?

Answer: Separation of concerns between business and data access layers Improved testability (can mock repositories) Centralized query logic for maintainability Easier to switch persistence implementations Promotes cleane…

SOLID Read answer
Mid PDF
How do you handle complex queries in the Repository pattern?

Add custom methods in a specialized repository interface (e.g., IProductRepository) Use Specification pattern or LINQ expressions Inject DbContext into repository if needed for advanced queries Optionally, break out comp…

SOLID Read answer
Mid PDF
What are potential drawbacks of Repository pattern?

Over-abstraction: Can add unnecessary complexity for simple apps. Duplication: May duplicate what EF Core already provides (since EF is already a repository/unit-of-work pattern). Hides EF Core features: May obscure adva…

SOLID Read answer
Mid PDF
How does Unit of Work complement the Repository pattern?

The Repository pattern abstracts the data access layer, providing a simplified interface to data operations. The Unit of Work pattern complements it by managing multiple repositories nd ensuring that all changes made thr…

SOLID Read answer
Mid PDF
How do you implement Unit of Work in a .NET application?

In a .NET application (especially using Entity Framework), the Unit of Work is typically implemented around the DbContext, as it already tracks changes and handles transactions. Here's a simplified example: // IUnitOfWor…

SOLID Read answer
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
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
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

Design Patterns & SOLID Design Patterns in C# · SOLID

One common thread-safe implementation uses lazy initialization with Lazy<T>:

public sealed class Singleton
{
private static readonly Lazy<Singleton> instance = new
Lazy<Singleton>(() => new Singleton());
private Singleton() { }
public static Singleton Instance => instance.Value;
}

This approach ensures thread safety and lazy initialization without locks.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

  • Global state: Singleton can lead to hidden dependencies and make testing difficult.
  • Tight coupling: Other classes depend on the Singleton instance, reducing flexibility.
  • Concurrency issues: If not implemented thread-safe, it can cause race conditions.
  • Resource contention: Singleton might become a bottleneck if overused in

concurrent environments.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

container, though generally discouraged.

What interviewers expect

  • A clear definition tied to SOLID in Design Patterns & SOLID projects
  • Trade-offs (performance, maintainability, security, cost)
  • When you would and would not use it in production

Real-world example

In a production Design Patterns & SOLID application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in Design Patterns & SOLID architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Singletons can hinder unit testing because they introduce global state, making tests

dependent on a shared instance. This can cause tests to be flaky or order-dependent. To

mitigate this, use interfaces and dependency injection, or design the Singleton to allow

resetting its state for tests.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

  • Eager Initialization: The Singleton instance is created at the time of class loading.

It's simple but can waste resources if the instance is never used.

  • Lazy Initialization: The instance is created only when it is first accessed. It saves

resources but requires careful implementation for thread safety.

Factory pattern Q&A

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

  • Factory Method: Defines an interface for creating an object but lets subclasses

decide which class to instantiate. It uses inheritance and relies on subclass

overriding.

  • Abstract Factory: Provides an interface to create families of related or dependent

objects without specifying their concrete classes. It uses composition and is useful

when you need to create multiple related objects together.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

A simple example of Factory Method:

// Product interface

public interface IAnimal
{

void Speak();

}

// Concrete Products

public class Dog : IAnimal
{
public void Speak() => Console.WriteLine("Woof");
}
public class Cat : IAnimal
{
public void Speak() => Console.WriteLine("Meow");
}

// Factory

public class AnimalFactory
{
public static IAnimal CreateAnimal(string animalType)
{
return animalType.ToLower() switch
{

"dog" => new Dog(),

"cat" => new Cat(),

_ => throw new ArgumentException("Invalid animal type")

};

}
}

Usage:

var dog = AnimalFactory.CreateAnimal("dog");

dog.Speak(); // Outputs: Woof

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

  • Encapsulates object creation: Decouples client code from concrete classes.
  • Promotes code reuse: Centralizes object creation logic.
  • Enhances maintainability: Adding new types requires minimal changes to existing

code.

  • Supports polymorphism: Clients work with interfaces or base classes rather than

concrete types.

  • Improves testability: Can easily mock or swap factory implementations.
Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Yes! Factory pattern can complement Dependency Injection (DI) by abstracting complex

object creation logic, especially when the creation involves runtime parameters or complex

setup that DI containers can’t handle easily.

Example: Imagine a service that needs different data repositories based on a runtime

parameter.

public interface IRepository { void Save(); }
public class SqlRepository : IRepository { public void Save() =>

Console.WriteLine("Saving to SQL DB"); }

public class InMemoryRepository : IRepository { public void Save()
=> Console.WriteLine("Saving in Memory"); }
public interface IRepositoryFactory
{

IRepository CreateRepository(string repoType);

}
public class RepositoryFactory : IRepositoryFactory
{
public IRepository CreateRepository(string repoType)
{
return repoType.ToLower() switch
{

"sql" => new SqlRepository(),

"memory" => new InMemoryRepository(),

_ => throw new ArgumentException("Invalid repository

type")

};

}
}

// Consumer class with DI

public class Service
{
private readonly IRepositoryFactory _repositoryFactory;
public Service(IRepositoryFactory repositoryFactory)
{
_repositoryFactory = repositoryFactory;
}
public void SaveData(string repoType)
{
var repo = _repositoryFactory.CreateRepository(repoType);

repo.Save();

}
}

Here, DI injects the IRepositoryFactory while the factory manages object creation

based on runtime input. This promotes loose coupling and flexibility.

Strategy Design Pattern

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Example: Payment strategy selection

// Strategy Interface

public interface IPaymentStrategy
{

void Pay(decimal amount);

}

// Concrete Strategies

public class CreditCardPayment : IPaymentStrategy
{
public void Pay(decimal amount) => Console.WriteLine($"Paid

{amount} using Credit Card");

}
public class PayPalPayment : IPaymentStrategy
{
public void Pay(decimal amount) => Console.WriteLine($"Paid

{amount} using PayPal");

}

// Context

public class PaymentContext
{
private IPaymentStrategy _paymentStrategy;
public PaymentContext(IPaymentStrategy paymentStrategy)
{
_paymentStrategy = paymentStrategy;
}
public void ExecutePayment(decimal amount)
{

_paymentStrategy.Pay(amount);

}
}

Usage:

var context = new PaymentContext(new PayPalPayment());

context.ExecutePayment(200); // Outputs: Paid 200 using PayPal

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Answer: Payment gateways (Credit Card, PayPal, UPI, etc.) Sorting algorithms (QuickSort, MergeSort, BubbleSort) Authentication strategies (OAuth, JWT, LDAP) Compression algorithms (ZIP, RAR, TAR) Loggers (FileLogger, ConsoleLogger, DatabaseLogger)

What interviewers expect

  • A clear definition tied to SOLID in Design Patterns & SOLID projects
  • Trade-offs (performance, maintainability, security, cost)
  • When you would and would not use it in production

Real-world example

In a production Design Patterns & SOLID application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in Design Patterns & SOLID architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

It promotes the Open/Closed Principle by allowing you to add new strategies (algorithms

or behaviors) without modifying the existing code.

The context class uses an interface for the strategy, so new behavior can be added just by

creating a new class that implements the interface—no need to touch existing logic.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Aspect Strategy Pattern State Pattern

Purpose Encapsulates interchangeable

behaviors (algorithms).

Encapsulates states and transitions

between them.

Client

Control

Client decides which strategy to use. Object changes its own state

internally.

Behavior

Switch

Switched externally (e.g., passed as

parameter).

Switched internally (e.g., via

method call).

Example Payment method selection. Document lifecycle (Draft →

Published → Archived).

Repository Design Pattern

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Here's a basic example:

// Entity

public class Product
{
public int Id { get; set; }
public string Name { get; set; }
}

// Generic Repository Interface

public interface IRepository<T> where T : class
{

Task<IEnumerable<T>> GetAllAsync();

Task<T> GetByIdAsync(int id);

Task AddAsync(T entity);

void Update(T entity);

void Delete(T entity);

Task SaveAsync();

}

// EF Core implementation

public class Repository<T> : IRepository<T> where T : class
{
private readonly DbContext _context;
private readonly DbSet<T> _dbSet;
public Repository(DbContext context)
{
_context = context;
_dbSet = context.Set<T>();
}
public async Task<IEnumerable<T>> GetAllAsync() => await

_dbSet.ToListAsync();

public async Task<T> GetByIdAsync(int id) => await

_dbSet.FindAsync(id);

public async Task AddAsync(T entity) => await

_dbSet.AddAsync(entity);

public void Update(T entity) => _dbSet.Update(entity);
public void Delete(T entity) => _dbSet.Remove(entity);
public async Task SaveAsync() => await

_context.SaveChangesAsync();

}
Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

Answer: Separation of concerns between business and data access layers Improved testability (can mock repositories) Centralized query logic for maintainability Easier to switch persistence implementations Promotes cleaner and more organized code

What interviewers expect

  • A clear definition tied to SOLID in Design Patterns & SOLID projects
  • Trade-offs (performance, maintainability, security, cost)
  • When you would and would not use it in production

Real-world example

In a production Design Patterns & SOLID application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.

How to explain in the interview

  1. Define the concept in one or two sentences.
  2. Context — where it fits in Design Patterns & SOLID architecture.
  3. Example — a specific project, bug, or performance win.
  4. Trade-off — what you gain vs what you sacrifice.

Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

  • Add custom methods in a specialized repository interface (e.g.,

IProductRepository)

  • Use Specification pattern or LINQ expressions
  • Inject DbContext into repository if needed for advanced queries
  • Optionally, break out complex queries into Query objects or services
public interface IProductRepository : IRepository<Product>
{

Task<IEnumerable<Product>> GetProductsWithLowStockAsync(int

threshold);

}
Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

  • Over-abstraction: Can add unnecessary complexity for simple apps.
  • Duplication: May duplicate what EF Core already provides (since EF is already a

repository/unit-of-work pattern).

  • Hides EF Core features: May obscure advanced capabilities like eager loading or

projections.

  • Extra boilerplate: Especially with generic repositories, which may not add much

value.

Unit of Work

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

The Repository pattern abstracts the data access layer, providing a simplified interface to

data operations. The Unit of Work pattern complements it by managing multiple repositories

nd ensuring that all changes made through these repositories are committed in a single

transaction. This combination separates concerns, promotes clean architecture, and

maintains transactional integrity across multiple operations.

Permalink & share

Design Patterns & SOLID Design Patterns in C# · SOLID

In a .NET application (especially using Entity Framework), the Unit of Work is typically

implemented around the DbContext, as it already tracks changes and handles

transactions. Here's a simplified example:

// IUnitOfWork.cs

public interface IUnitOfWork : IDisposable
{

IProductRepository Products { get; }

ICustomerRepository Customers { get; }

int Complete();
}

// UnitOfWork.cs

public class UnitOfWork : IUnitOfWork
{
private readonly AppDbContext _context;
public IProductRepository Products { get; private set; }
public ICustomerRepository Customers { get; private set; }
public UnitOfWork(AppDbContext context)
{
_context = context;
Products = new ProductRepository(_context);
Customers = new CustomerRepository(_context);
}
public int Complete()
{
return _context.SaveChanges(); // All changes in one

transaction

}
public void Dispose()
{

_context.Dispose();

}
}

Then register it using Dependency Injection in Startup.cs or Program.cs:

services.AddScoped<IUnitOfWork, UnitOfWork>();

Permalink & share

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

.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

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
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