Use the new HttpClientFactory to create HttpClient objects in ASP.NET Core. Learn how to create Named or Typed HttpClient instances.
With .NET Core 2.1 the HttpClientFactory is introduced. The HttpClientFactory is a factory class which helps with managing HttpClient instances. Managing your own HttpClient correctly was not so easy. The HttpClientFactory gives you a number of options for easy management of your HttpClient instances. In this post I’ll explain how to use the HttpClientFactory in your ASP.NET Core application.
Continue reading “HttpClient and HttpClientFactory in ASP.NET Core”
Enable Soft-delete for Key Vault to be able to recover from disaster, recover keys, secrets, certificates or the whole Key Vault on accedental deletion.
Last week we had an incident in which we had deleted the wrong secret from our Azure Key Vault. After some research we found that it could have been recovered if we had used the Soft-delete in Key Vault. However, we did not know about this option and could not recover the item.
Continue reading “Azure Key Vault recover keys, secrets and certificates”
Check the operating system .NET Core is running on. Sometimes there are small differences when running on Linux or Windows. Discover your OS without exceptions.
There are a few cases where it is very useful to know the OS your .NET Core application is running on. One of those cases is when you need to set a time zone. Each OS does have its own naming of time zones. You can just try and catch the exception and then retry for another OS, however, if you know the OS, then it is far nicer to do this without exception handling.
Continue reading “.NET Core, what is my OS”
Cannot consume scoped service ‘IScoped’ from singleton ‘Microsoft.Extensions.Hosting.IHostedService’.
In our projects we are using IHostedService to run background processes. What I have seen is that when injecting a scoped service into the IHostedService you get a
InvalidOperationException on startup. The first time you get this exception, it is takes some time to figure out what is going on. This blog post will help you to resolve the problem faster.
Continue reading “Injecting a Scoped service into IHostedService”
Azure SQL, do not forget to schedule maintenance
Many users on Azure SQL Server do not realize they have to do their own maintenance on Indexes. This index will slowly become fragmented and the performance will decrease over time. Azure SQL does not have a Job scheduler (agent) like on premise. In this post I’ll describe how to schedule a maintenance job from an ASP.NET Core application.
Continue reading “Run maintenance jobs on Azure SQL”
Only a few years back Windows Communication Foundation (WCF) was the way to do communication on the Microsoft platform based on SOAP protocol. Now a days new services are mostly build on top of Representational State Transfer (REST) Services. Sometimes you have to access a ‘legacy’ SOAP services for .NET Core. .NET Core has limited WCF support. In this blog post I’ll explain how to consume SOAP services form .NET Core.
Continue reading “Access XML SOAP services in .NET Core and client certificates (SSL)”
In the previous blog post called background tasks with ASP.NET Core using the IHostedService Peter described how to use the IHostedInterface for background tasks. In this post, we continue on this subject and add some pointers on how to perform scheduled background tasks.
In many software projects, there are repetitive tasks; some do just repeat every x seconds after the last instance is finished but you might also have to run a task on a schedule like every 10 minutes. When building repeating or scheduled tasks there are many options on how to approach the scheduling and this approach can be influenced by a number of technical choices.
Building the scheduling yourself is an option when you do not want to add extra dependencies to your project, have full control or just want an extra technical challenge. An out of the box solution you can a look at Hangfire, Quartz.net, or an external service that does an http call every x seconds to trigger the task (something like Pingdom).
Continue reading “Run scheduled background tasks in ASP.NET Core”