read configuration workerservice
C#
public class Program {
public static void Main(string[] args) {
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) => {
IConfiguration configuration = hostContext.Configuration;
WorkerOptions options = configuration
.GetSection("WCF")
.Get<WorkerOptions>();
services.AddSingleton(options);
services.AddHostedService<Worker>();
});
}
public class Worker : BackgroundService {
private readonly ILogger<Worker> logger;
private readonly WorkerOptions options;
public Worker(ILogger<Worker> logger, WorkerOptions options) {
this.logger = logger;
this.options = options;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken) {
while (!stoppingToken.IsCancellationRequested) {
//do something that uses options
logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
await Task.Delay(5000, stoppingToken);
}
}
}
public class WorkerOptions {
public string AminServiceUri { get; set; }
public string BillServiceUri { get; set; }
//... other properties
}
//File appsettings.json
{
"WCF": {
"AminServiceUri":"http://localhost:45108/ServiceHost/v1/AminService.svc",
"BillServiceUri":"http://localhost:45108/ServiceHost/v1/BillService.svc",
//...other key-value pairs
},
"Logging": {
"ExcessiveLogging": false
}
}
Also in C#:
- Title
- c# format string to date yyyymmdd
- Category
- C#
- Title
- interop C# save as and replace
- Category
- C#
- Title
- c# replace string case insensitive
- Category
- C#
- Title
- how to get length of okobjectresult c#
- Category
- C#
- Title
- how to trigger event when a com device is connected in c#
- Category
- C#
- Title
- c# arrays of arrays
- Category
- C#
- Title
- convert word files to plain text c#
- Category
- C#
- Title
- what type of variable is true or false in c#
- Category
- C#
- Title
- Move player on planets in unity 2d
- Category
- C#
- Title
- how to cast list to observablecollection c#
- Category
- C#
- Title
- while loop in c#
- Category
- C#
- Title
- c#if
- Category
- C#
- Title
- c# pull request
- Category
- C#
- Title
- unity variable from another script
- Category
- C#
- Title
- percentage in c#
- Category
- C#
- Title
- C# public 2d array
- Category
- C#
- Title
- c# string to lowercase
- Category
- C#
- Title
- c# if statement
- Category
- C#
- Title
- unity gizmo draw line
- Category
- C#
- Title
- variables
- Category
- C#
- Title
- unity on trigger enter
- Category
- C#
- Title
- C# colours
- Category
- C#
- Title
- c# print
- Category
- C#
- Title
- how to cjeck if a string has a word c#
- Category
- C#
- Title
- unity 2d platformer movement script c#
- Category
- C#
- Title
- how to declare 2d array in c#
- Category
- C#
- Title
- how to flip selection in aseprite
- Category
- C#
- Title
- roulette algorithm genetic algorithm
- Category
- C#
- Title
- fahrenheit to celsius c#
- Category
- C#
- Title
- native-googlesignin configuration is null!?
- Category
- C#
- Title
- c# download file
- Category
- C#
- Title
- CS0103 C# The name 'Request.Url.Scheme' does not exist in the current context
- Category
- C#
- Title
- unity rotation
- Category
- C#
- Title
- unity onclick addlistener
- Category
- C#
- Title
- datagridview select row column cell c#
- Category
- C#
- Title
- unity docs player input
- Category
- C#
- Title
- how to select time and date in datetimepicker in c#
- Category
- C#
- Title
- csharp first element of array
- Category
- C#
- Title
- http post request login example asp.net c#
- Category
- C#
- Title
- how to access first child of parent unity
- Category
- C#
- Title
- how to add array to list in c#
- Category
- C#
- Title
- c# length of array
- Category
- C#
- Title
- mouseposition unity
- Category
- C#
- Title
- how to make a for loop in c#
- Category
- C#
- Title
- asp.net core task iactionresult
- Category
- C#
- Title
- movement script c#
- Category
- C#
- Title
- c# new list object
- Category
- C#
- Title
- declare string array c# without size
- Category
- C#
- Title
- how to get the last element in an array in c#
- Category
- C#
- Title
- unity c# write line
- Category
- C#
- Title
- loop gridcontrol devexpress c#
- Category
- C#
- Title
- beard styles without mustache Intitle:work with me
- Category
- C#
- Title
- c# expandoobject indexer
- Category
- C#
- Title
- unity button interactable
- Category
- C#
- Title
- c# sort for loop
- Category
- C#
- Title
- unity scene name get
- Category
- C#
- Title
- unity serializefield
- Category
- C#
- Title
- how to say or in c#
- Category
- C#
- Title
- unity set sprite transparency
- Category
- C#
- Title
- how to add an embedded resource in visual studio code
- Category
- C#
- Title
- disable a component unity
- Category
- C#
- Title
- c# directories loop
- Category
- C#
- Title
- c# find element by condition
- Category
- C#
- Title
- C# downloadstirng download old
- Category
- C#
- Title
- c# input integer
- Category
- C#
- Title
- c# get country code
- Category
- C#
- Title
- c# string array to string
- Category
- C#
- Title
- how to exit a program in c#
- Category
- C#
- Title
- transform object according to its parent unity
- Category
- C#
- Title
- c# verify in class exist in list
- Category
- C#
- Title
- how to record number of times using application in c#
- Category
- C#
- Title
- unity get data from firebase
- Category
- C#
- Title
- The type or namespace name 'Scrollbar' could not be found
- Category
- C#
- Title
- making a list of chars in c#
- Category
- C#
- Title
- Add component object to gameobject unity
- Category
- C#
- Title
- How to execute script in C#
- Category
- C#
- Title
- unity load scene
- Category
- C#
- Title
- how to make if statement c#
- Category
- C#
- Title
- c# linq select from object list
- Category
- C#
- Title
- c# remove last character from string
- Category
- C#
- Title
- c# get binary array from int
- Category
- C#
- Title
- Category
- C#
- Title
- c# get motherboard id
- Category
- C#
- Title
- c# zip a file
- Category
- C#
- Title
- how to change an int value c#
- Category
- C#
- Title
- count the number of notes in a given amount c#
- Category
- C#
- Title
- string to guid c#
- Category
- C#
- Title
- c# System.Resources.MissingManifestResourceException error
- Category
- C#
- Title
- degree between two points latitude longitude c#
- Category
- C#
- Title
- as c#
- Category
- C#
- Title
- go right unity
- Category
- C#
- Title
- how to stop window from terminating c# visual studio
- Category
- C#
- Title
- c# lambda expression
- Category
- C#
- Title
- unity material offset script
- Category
- C#
- Title
- leantween move ui
- Category
- C#
- Title
- remove all array elements c#
- Category
- C#
- Title
- c# window instantly close
- Category
- C#
- Title
- c# reverse a string for loop
- Category
- C#
- Title
- how to pass object as test case in nunit c#
- Category
- C#
- Title
- c# delay
- Category
- C#