DEV Community

Cover image for Azure & DevOps mastery for scalable .NET applications
Libin Tom Baby
Libin Tom Baby

Posted on

Azure & DevOps mastery for scalable .NET applications

Azure & DevOps mastery for scalable .NET applications


1. How different or similar are dependency injection and dependency inversion? How do you implement them?

  • Dependency Inversion Principle (DIP): High-level modules should depend on abstractions, not concrete implementations.
  • Dependency Injection (DI): A design pattern that fulfills DIP by injecting dependencies into classes.

In .NET:

services.AddTransient<IMyService, MyService>();
Enter fullscreen mode Exit fullscreen mode

This decouples your logic, improves testability, and aligns with SOLID principles.


2. An interface has multiple implementations. How do you manage the mapping in Program.cs?

Use factories or named registrations. For example:

services.AddTransient<IMyService, MyService1>();
services.AddTransient<IMyService, MyService2>();
Enter fullscreen mode Exit fullscreen mode

Then resolve using a factory or conditional logic based on context.


3. How do you establish DB connectivity in Entity Framework?

Configure DbContext with a connection string:

services.AddDbContext<MyDbContext>(options =>
    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
Enter fullscreen mode Exit fullscreen mode

This sets up EF Core to connect to SQL Server using DI.


4. What’s the difference between DB First and Code First in EF?

Approach Description
DB First Start with an existing database; scaffold models
Code First Start with C# classes; EF generates schema

Use DB First for legacy systems. Use Code First for greenfield development.


5. How do you create a new table using Code First in EF?

Define a model and add a DbSet:

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

public class MyDbContext : DbContext {
    public DbSet<MyNewTable> MyNewTables { get; set; }
}
Enter fullscreen mode Exit fullscreen mode

Then run:

dotnet ef migrations add AddMyNewTable
dotnet ef database update
Enter fullscreen mode Exit fullscreen mode

6. What are return types of API controllers and how do they differ?

Return Type Framework Description
IActionResult ASP.NET Core Flexible, supports multiple response types
IHttpActionResult ASP.NET Web API Older, used for HTTP response abstraction

Use IActionResult for modern APIs—it integrates well with filters and middleware.


7. Is concurrency the same as asynchronous programming?

No. Concurrency is about multiple tasks running simultaneously. Asynchronous programming is about non-blocking operations.

public async Task<IActionResult> GetDataAsync() {
    var data = await _service.GetDataAsync();
    return Ok(data);
}
Enter fullscreen mode Exit fullscreen mode

Async improves scalability. Concurrency improves throughput.


8. What caching mechanisms have you used?

  • In-memory caching: Fast, scoped to app instance.
  • Distributed caching: Scalable, e.g., Redis.
  • Output caching: For static content.
services.AddMemoryCache();
_cache.Set("key", value, TimeSpan.FromMinutes(5));
Enter fullscreen mode Exit fullscreen mode

9. How do you implement sliding expiration in caching?

var cacheEntryOptions = new MemoryCacheEntryOptions {
    SlidingExpiration = TimeSpan.FromMinutes(5)
};

_cache.Set("EmployeeDetails", employeeDetails, cacheEntryOptions);
Enter fullscreen mode Exit fullscreen mode

This resets the expiration timer on each access.


10. What’s the difference between sliding and absolute expiry?

Expiry Type Behavior
Sliding Expiry Resets on each access
Absolute Expiry Expires after fixed time, regardless of access

Use sliding for frequently accessed data. Use absolute for predictable cleanup.


11. How can you pass an array of records from EF to the database?

Use AddRange:

context.MyEntities.AddRange(myEntitiesArray);
context.SaveChanges();
Enter fullscreen mode Exit fullscreen mode

Efficient for bulk inserts.


12. What are defined tables in relation to stored procedures?

Defined tables are explicitly created in the database schema. They’re referenced in stored procedures for input/output operations and table-valued parameters.


13. What’s clean architecture?

Clean architecture separates your app into layers:

  • Domain: Core business logic
  • Application: Use cases and orchestration
  • Infrastructure: DB, APIs, external services

This improves testability, scalability, and maintainability.


Top comments (0)