𝐄𝐱𝐩𝐥𝐨𝐫𝐢𝐧𝐠 𝐈𝐇𝐨𝐬𝐭𝐞𝐝𝐒𝐞𝐫𝐯𝐢𝐜𝐞 𝐢𝐧 .𝐍𝐄𝐓 𝐂𝐨𝐫𝐞 💡 𝐖𝐡𝐚𝐭 𝐢𝐬 𝐈𝐇𝐨𝐬𝐭𝐞𝐝𝐒𝐞𝐫𝐯𝐢𝐜𝐞? In .NET Core, IHostedService is an interface designed for running background tasks. Think of it as a way to run services that live alongside your main application without blocking its primary operations. IHostedService implementations can start tasks when your application starts and gracefully stop them when the application is shutting down. 🔧 𝐂𝐨𝐦𝐦𝐨𝐧 𝐔𝐬𝐞 𝐂𝐚𝐬𝐞𝐬 𝐟𝐨𝐫 𝐈𝐇𝐨𝐬𝐭𝐞𝐝𝐒𝐞𝐫𝐯𝐢𝐜𝐞 1. 𝐁𝐚𝐜𝐤𝐠𝐫𝐨𝐮𝐧𝐝 𝐉𝐨𝐛𝐬: Perfect for periodic data processing, cleanup tasks, or sending scheduled notifications. 2. 𝐋𝐨𝐧𝐠-𝐫𝐮𝐧𝐧𝐢𝐧𝐠 𝐏𝐫𝐨𝐜𝐞𝐬𝐬𝐞𝐬: Useful for processes that need to persist across the app's lifecycle, like monitoring a queue. 3. 𝐄𝐯𝐞𝐧𝐭 𝐋𝐢𝐬𝐭𝐞𝐧𝐞𝐫𝐬: Ideal for apps that listen for changes in real-time, such as handling messages from message queues like RabbitMQ. 4. 𝐃𝐚𝐭𝐚 𝐅𝐞𝐭𝐜𝐡𝐢𝐧𝐠 𝐒𝐞𝐫𝐯𝐢𝐜𝐞𝐬: Great for services that require regular updates from an external API. 💼 𝐖𝐡𝐞𝐧 𝐭𝐨 𝐔𝐬𝐞 𝐈𝐇𝐨𝐬𝐭𝐞𝐝𝐒𝐞𝐫𝐯𝐢𝐜𝐞? 1. 𝐑𝐞𝐜𝐮𝐫𝐫𝐢𝐧𝐠 𝐁𝐚𝐜𝐤𝐠𝐫𝐨𝐮𝐧𝐝 𝐓𝐚𝐬𝐤𝐬: Tasks like sending emails, syncing data, or cleaning up files work well with IHostedService. 2. 𝐀𝐩𝐩𝐥𝐢𝐜𝐚𝐭𝐢𝐨𝐧-𝐖𝐢𝐝𝐞 𝐋𝐢𝐬𝐭𝐞𝐧𝐞𝐫𝐬: Monitoring queues, websockets, or real-time events. 3. 𝐀𝐬𝐲𝐧𝐜𝐡𝐫𝐨𝐧𝐨𝐮𝐬 𝐎𝐩𝐞𝐫𝐚𝐭𝐢𝐨𝐧𝐬: When you need something to run independently of the main application thread, IHostedService is a perfect fit. #dotnetcore #IHostedService #BackgroundTasks #CSharp #AsyncProgramming #Microservices
Chirag Baroliya’s Post
More Relevant Posts
-
API Architectural Styles: Which One Should You Choose? 🤔 APIs are the backbone of modern software systems, but did you know there are several architectural styles you can choose from? Each has its own strengths, depending on your use case. 🔍 Here's a quick breakdown: 1️⃣ SOAP: A protocol-based approach with built-in security, ideal for handling transactions. 2️⃣ REST: Uses standard HTTP methods with statelessness for scalability. Perfect for web services that need simplicity and flexibility. 3️⃣ gRPC: High-performance and ideal for microservices, using Protocol Buffers for efficient data exchange. 4️⃣ GraphQL: Gives clients the power to request exactly the data they need, making it a great choice for mobile apps with varied data requirements. 5️⃣ WebSockets: Enables real-time, full-duplex communication for applications like chat systems and live updates. 6️⃣ Webhook: Event-driven and asynchronous, allowing servers to send real-time updates to clients without constant polling. 🔗 Each style has its strengths. Choosing the right one depends on your project’s needs—whether it's security, performance, or flexibility. What’s your preferred API architectural style and why? Let’s discuss in the comments below! 🚀 Follow: Hamza Ali Khalid #API #SoftwareDevelopment #WebDevelopment #REST #SOAP #gRPC #GraphQL #WebSockets #Webhook #TechLeadership
To view or add a comment, sign in
-
"The Essential Guide to APIs: REST, Soap, GraphQL, etc.." APIs (Application Programming Interfaces) enable different software applications to communicate and interact. There are several types of APIs, each with specific purposes and working principles: 1. Open APIs are public and accessible to external developers, often used for services like social media or maps. 2. Internal APIs are restricted to internal use within a company, facilitating data sharing between departments. 3. Partner APIs allow access to specific third-party partners with controlled authorization. 4. Composite APIs bundle multiple service calls into one, optimizing performance for complex operations. 5. REST APIs follow a flexible, stateless approach, using HTTP methods like GET and POST. 6. SOAP APIs offer high security and structured data handling commonly used in banking. 7. GraphQL APIs provide precise data retrieval, allowing clients to specify exactly what they need. 8. WebSocket APIs enable real-time, two-way communication, ideal for live applications 9. Library-Based APIs allow developers to use predefined functions within specific libraries. 10. Operating System APIs enable interactions with OS functions, such as file handling and graphics. #APIlntegration #APIDevelopment #RESTvsSOAP #GraphQL #WebAPIs
To view or add a comment, sign in
-
Just Released: RESTFulSense 2.18.0 This release supports getting a byte array from an API endpoint. It's now available for both server-side and WASM. Thanks to Elbek Normurodov for developing this capability. #restfulapi #dotnet #csharp https://lnkd.in/gdpdprry
To view or add a comment, sign in
-
𝐓𝐲𝐩𝐞𝐬 𝐨𝐟 𝐀𝐏𝐈𝐬 𝐄𝐱𝐩𝐥𝐚𝐢𝐧𝐞𝐝 APIs power modern software communication, and here’s a quick rundown of four popular types: 1. 𝐑𝐄𝐒𝐓 𝐀𝐏𝐈 (𝐑𝐞𝐩𝐫𝐞𝐬𝐞𝐧𝐭𝐚𝐭𝐢𝐨𝐧𝐚𝐥 𝐒𝐭𝐚𝐭𝐞 𝐓𝐫𝐚𝐧𝐬𝐟𝐞𝐫) 🌐 A widely used web API design over HTTP. Uses URLs to identify resources and standard HTTP methods like GET, POST, PUT, and DELETE for operations. 2. 𝐒𝐎𝐀𝐏 𝐀𝐏𝐈 (𝐒𝐢𝐦𝐩𝐥𝐞 𝐎𝐛𝐣𝐞𝐜𝐭 𝐀𝐜𝐜𝐞𝐬𝐬 𝐏𝐫𝐨𝐭𝐨𝐜𝐨𝐥) 🧼 A protocol for exchanging structured data, common in enterprise apps. Uses XML for message format, enforcing strict structure. 3. 𝐆𝐫𝐚𝐩𝐡𝐐𝐋 𝐀𝐏𝐈 🔍 A query language allowing clients to request specific data. Clients define the response structure, making it efficient by avoiding over-fetching or under-fetching. 4. 𝐖𝐞𝐛𝐒𝐨𝐜𝐤𝐞𝐭 𝐀𝐏𝐈 💬 Enables real-time, two-way communication over a persistent connection. Ideal for live notifications, chat applications, and gaming. Each API type is tailored for different use cases, making them all valuable in their own right! #APIs #REST #SOAP #GraphQL #WebSockets
To view or add a comment, sign in
-
Part 2 𝐰𝐡𝐚𝐭 𝐚𝐫𝐞 𝐬𝐲𝐧𝐜𝐡𝐫𝐨𝐧𝐨𝐮𝐬 𝐚𝐜𝐭𝐢𝐨𝐧 𝐟𝐢𝐥𝐭𝐞𝐫𝐬? ⚡ They are used to synchronously perform custom processing before or after action is executed. They are executed in the in a blocking manner, the tasks have to complete before allowing the requests to proceed. They are mostly used on controllers actions. They work together with the request pipeline to process custom logics you want to perform depending on your requirement. Can also be used for: - Authorization - Authentication(demonstrated now) - Logging - Caching - Error handling(I demonstrated with async filter few weeks back, will put the link in comment) etc. In this part, I demonstrated how to use synchronous action filter by using one of the use cases(Authentication). It confirms that the header key is correct before processing the action method. Synchronous action filter has functions implemented from IActionFilter interface. - 𝐎𝐧𝐀𝐜𝐭𝐢𝐨𝐧𝐄𝐱𝐞𝐜𝐮𝐭𝐢𝐧𝐠 function is processed before the action is called. Logic here should be what to do before executing the action. - 𝐎𝐧𝐀𝐜𝐭𝐢𝐨𝐧𝐄𝐱𝐞𝐜𝐮𝐭𝐞𝐝 function is processed after the action is called or before the IActionResult is returned. Logic here should be what you want to do after the action is executed, like error handling for any error that occurs during the processing of the action etc.. Synchronous action filter is also useful as: - They're easier to implement and understand, especially for developers new to the .NET framework. - They guarantee a specific order of execution, which can be crucial for certain operations. - They have direct access to the action's context without dealing with async/await patterns. - Some older systems or libraries may not support asynchronous operations. However, they are not commonly used as asynchronous action filters are generally preferred in modern .NET applications, especially for I/O-bound operations, as they can improve application scalability and responsiveness. If you missed my part 1 for asynchronous action filters👇 Have a good read: https://lnkd.in/e_xD-M5V If you enjoyed this post, please repost🔁 to let others see. Reach out to Philip Kayode, PHILSKAY #softwareengineering #softwaredevelopment #csharp #dotnet #dotnetcore #tech
To view or add a comment, sign in
-
#WhatsNewInDotNET9 .NET 9 introduces significant advancements across the ecosystem, catering to modern app development needs, including AI, security, and performance. .NET 9 focuses on cloud-native apps, performance, AI integration, and enhanced developer productivity. It is a standard-term support (STS) release supported for 18 months. #KeyHighlights: #DotNETRuntime: Feature Switches: New attribute model with trimming support. Garbage Collection: Dynamic adaptation for app size (default over Server GC). Performance Enhancements: Loop optimizations, inlining, and Arm64 improvements. #DotNETLibraries: System.Text.Json: Nullable reference types, JSON schema export, custom indentation, multi-root JSON parsing. LINQ: New CountBy and AggregateBy methods for key-based aggregation. Collections: PriorityQueue adds a method for updating item priorities. Cryptography: One-shot hash method and KMAC algorithm support. Reflection: New PersistedAssemblyBuilder with PDB debugging support. TimeSpan: Int-based From* methods for precision. #DotNETSDK: Workload Sets: Unified versioning for workloads. Tooling: User control over tool runtime compatibility. Improvements: Parallel unit testing with better MSBuild integration. Automatic NuGet security audits. Enhanced terminal logger and new MSBuild script analyzers. #ASPDotNETCore: Performance: Faster startup, optimized static file handling. Blazor: New templates, render mode detection, reconnection experience. APIs: OpenAPI document generation, enhanced AOT support. Security: New APIs for authentication/authorization. #Note: If you want to learn more about the new release and improvements to the key cornerstone, please take a look at this official document: https://lnkd.in/gAmJgrTW
What's new in .NET 9
learn.microsoft.com
To view or add a comment, sign in
-
I'm going to shamelessly promote thart, a new open-source library for managing multi-process Node.js applications. Whether you're building scalable web servers or complex data processing systems, thart simplifies the challenges of starting your Node.js application with multiple processes. Key Features of thart: - Easily spawn and manage multiple worker processes - Graceful and coordinated shutdown handling - Per worker configurable startup and shutdown behaviors - Flexible API supporting various application structures thart is available now via npm. https://lnkd.in/gYkbYEB2
thart
npmjs.com
To view or add a comment, sign in
-
"The Essential Guide to APIs: REST, SOAP, GraphQL, and Beyond" APIs (Application Programming Interfaces) enable different software applications to communicate and interact. There are several types of APIs, each with specific purposes and working principles: 1. Open APIs are public and accessible to external developers, often used for services like social media or maps. 2. Internal APIs are restricted to internal use within a company, facilitating data sharing between departments. 3. Partner APIs allow access to specific third-party partners with controlled authorization. 4. Composite APIs bundle multiple service calls into one, optimizing performance for complex operations. 5. REST APIs follow a flexible, stateless approach, using HTTP methods like GET and POST. 6. SOAP APIs offer high security and structured data handling, commonly used in banking. 7. GraphQL APIs provide precise data retrieval, allowing clients to specify exactly what they need. 8. WebSocket APIs enable real-time, two-way communication, ideal for live applications. 9. Library-Based APIs allow developers to use pre-defined functions within specific libraries. 10. Operating System APIs enable interactions with OS functions, such as file handling and graphics. #APIIntegration #APIDevelopment #RESTvsSOAP #GraphQL #WebAPIs
To view or add a comment, sign in
-
.NET 8 introduces significant performance enhancements, such as optimized Just-In-Time (JIT) compilation and enhanced garbage collection. These updates are vital for developers focusing on high-performance applications. Stay updated on these improvements here: https://lnkd.in/eQvwwyzg
.Net 8 tips
dev.to
To view or add a comment, sign in
-
𝐈𝐦𝐩𝐥𝐞𝐦𝐞𝐧𝐭𝐢𝐧𝐠 𝐅𝐞𝐚𝐭𝐮𝐫𝐞 𝐅𝐥𝐚𝐠𝐬 𝐢𝐧 .𝐍𝐄𝐓 𝐂𝐨𝐫𝐞 🚀 Feature flags are game-changers for managing features in your .NET Core applications. They allow you to control which features are active without needing to redeploy your code. This is perfect for gradual rollouts, A/B testing, and toggling features on or off based on real-time conditions. Here's a quick guide on how to get started: 1 - 𝐃𝐞𝐟𝐢𝐧𝐞 𝐘𝐨𝐮𝐫 𝐅𝐞𝐚𝐭𝐮𝐫𝐞 𝐅𝐥𝐚𝐠𝐬: Use configuration settings like appsettings.json to manage your flags. 2 - 𝐀𝐜𝐜𝐞𝐬𝐬 𝐅𝐥𝐚𝐠𝐬 𝐢𝐧 𝐂𝐨𝐝𝐞: Read flag values and adjust feature logic accordingly. 3 - 𝐔𝐬𝐞 𝐅𝐞𝐚𝐭𝐮𝐫𝐞 𝐌𝐚𝐧𝐚𝐠𝐞𝐦𝐞𝐧𝐭 𝐋𝐢𝐛𝐫𝐚𝐫𝐢𝐞𝐬: For advanced scenarios, libraries like Microsoft.FeatureManagement can be used. 4 - 𝐒𝐭𝐨𝐫𝐞 𝐅𝐥𝐚𝐠𝐬 𝐢𝐧 𝐚 𝐃𝐚𝐭𝐚𝐛𝐚𝐬𝐞:You can also store feature flags in a database, giving you more control. Pair this with an admin UI to dynamically update flags and configure features at runtime without redeployment. Feature flags give you the flexibility to manage features efficiently, monitor performance, and respond to feedback quickly. 💡 Dive into the details and optimize your application management! #DotNetCore #FeatureFlags #SoftwareDevelopment #ASPNetCore #ProgrammingTips #FeatureManagement #CSharp #TechTips #SoftwareEngineering
To view or add a comment, sign in