I want to rewrite my current webjobs config to the version 3.0 but I can't get it to work with the documentation because I have no idea how to set the dashboardconnectionstring
or storageconnectionstring
without a config file.
JobHostConfiguration config = new JobHostConfiguration
{
NameResolver = new WebJobsNameResolver()
};
string defaultStorageConnectionString = string.Format( "Some dynamically generation string" );
config.DashboardConnectionString = defaultStorageConnectionString;
config.StorageConnectionString = defaultStorageConnectionString;
using(JobHost host = new JobHost(config))
{
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
I want to make it run continuously with the correct storage and dashboard connection string, without using a config file.
The 3.0.0 NuGet package update (non-beta) brought breaking changes. It's based on the generic host which is similar to the asp.net host. You could refer to the steps as below:
1.Add this line of code in your program.cs.
The whole code in Program.cs.
2.Set
appsettings.json
(note that set it's propertyCopy to Output Directory
orCopy always
):3.Functions.cs:
4.The output:
For more details, you could refer to this tutorial.
Update:
As Joey said, we could use
with
So that it will not use the config file. Here is the article about how to use
AddInMemoryCollection