Skip to main content

Posts

Showing posts with the label APIdevelopment

Report generation in .Net Core API

  In this tutorial we will learn about quick way to generate reports using .net core api. When we work in companies, we may face a situation where client ask to generate reports, and he is not ready to spend money in purchasing third party libraries to get reports. Apart from this he want to work to done in same day or he has some urgency. In this situation this tutorial will helpful where we need to generate reports in single day without spending and wasting time in research. Let’s Start. a. We will create .Net core API. b. Create Endpoint for Download file c. Make a call to database and fetch data. d. Create report in html format and send html file back to user as response. Consider we connect to database and get below data table Consider code below using Microsoft.AspNetCore.Mvc; using System.Data; using System.Text; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 namespace DownloadFile.Controllers { [ ...

Fixing Incorrect Scope Injection of Services in .Net Core

Sometimes we inject Scope Services into singleton Services which may cause incorrect behavior of application, we will see how we can identify those objects or services Incorrect Dependency Injection Identifying and resolving issues caused by incorrect scope injection in services is crucial for maintaining the integrity and performance of a .NET Core application. Incorrectly scoped services can lead to unintended behavior, performance issues, or memory leaks. It is very important to understand Lifetime of object in .NET core and how to register with incorrect lifetime. Key rules Transient services  can be injected into any other lifetime. Scoped services  can be injected into other scoped services, or into transient services, but  not into singletons . Singleton services  can only safely inject other singletons,  not scoped or transient services . Why? Scoped services  are disposed at the end of a request. Injecting a scoped service into a singleton would me...

Architecting Resilient .NET Core Applications: Handling Transient Failures.

  Transient Failures happen when server is temporarily overloaded.  We need to handle this instead of sending response back to client and say like that “Server is not responding” In the world of Cloud there are temporary failures that may occur in a system and can be recovered from by retrying the operation. T hese failures typically occur due to network issues, temporary unavailability of external services, timeouts, or rate limiting, and they often resolve themselves after a brief period. Possible Reasons for Transient Failures Resource overloaded:   For example, in high-traffic scenarios, limited system resources (like memory or CPU) can lead to failures when trying to access those resources. Network Issues :  Temporary issues like DNS resolution errors, dropped connections, or network congestion can cause operations to fail. Service Unavailability :  External services or databases might be down or unavailable temporarily.  For example, a database connec...