C
C#

help

❔ Passing parameters to Services

Aalkasel#15911/21/2022
Hi, I've a webapp where, at start, I parse some configuration values from
appssettings.json
appssettings.json
Then, from these configuration values, I'd like to build some object and passing them to services. Please note these services could have other services injected into them. Should I have classes representing configuration objects, make them services, use
GetRequestService
GetRequestService
to initialize them and finally inject them into other services?
PPobiega11/21/2022
This sounds a lot like what Microsoft.Extensions.Configuration already does with its IOption<T> interface essentially, you specify a "section" of your configuration and that part of the config gets deserialized into an object that is then stored in your DI container in your services that then need access to the configuration values, you simply add a IOptions<MyConfigObject> options to your service constructor and voila, you have access to a strongly typed instance of the config
Aalkasel#15911/21/2022
Nice, thank you for the tip! I've finished working for today, but tomorrow I'll definitely give it a try!
PPobiega11/21/2022
Configuration in ASP.NET Core
Learn how to use the Configuration API to configure AppSettings in an ASP.NET Core app.
PPobiega11/21/2022
this page covers the details. ignore the razor stuff 😛
services.Configure<PositionOptions>(
config.GetSection(PositionOptions.Position));
services.Configure<ColorOptions>(
config.GetSection(ColorOptions.Color));
services.Configure<PositionOptions>(
config.GetSection(PositionOptions.Position));
services.Configure<ColorOptions>(
config.GetSection(ColorOptions.Color));
AAccord11/22/2022
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
❔ Abstracting html in RazorI want to define custom components to abstract away some html content. These should be able to accepPinging localhost [Answered]The block below is a method that compiles without issue. However, when I try and pass it localhost:8Expression returns false even though it should return trueHi, I'm trying to check if a date is before now or after NOW. While debugging i can see that the exp❔ How to bind DateTime in query parameter?Hi, any tips how I can pass a DateTime as a query parameter? I'm doing an Http request from one api❔ Foreach loopI am trying to run through my list, but nothing is being printed out, what am I doing wrong? ```cs Calculate obj Age [Answered]**Program** ```cs DateTime dtBirthDate = new DateTime(1971, 2, 23); ``` **Student** ```cs public Dat❔ Removing JSON data from JSON FileHey, I am attempting to remove JSON data from a text file if required (I'm using it as a local datab❔ DateTime Property [Answered]```cs public DateTime DateOfTime { get { return _DateOfTime; } ❔ Database ID not beginning from 1?Hello all, complete noob to .NET here. I have successfully seeded my database with some data in ASP.❔ How can I access a member of a different class in a dictionaryHey! I'm trying to refactor my old JSON serializer code, but I ran into an issue. I can't access a s❔ Does nopcommerce support blazor in. Net 6?I would like to know if blazor server for. Net 6 is supported in nopcommerce In the nopcommerce doc❔ Quickest way to get an async function to run?I have an async function with an await inside and I'm currently using Task.Run to start it, but ther❔ Query won't filterI am trying to filter by one of these two search options, they both show up properly in the network ❔ Should I separate the add and edit page in a web app?Ive always combined the add and edit page since the html is the same in both page. Depending if i ha❔ DI QuestionI have this code for setting up DI in my worker service project https://pastebin.com/6HH5sBAx But wAzure Functions output binding to HTTP request (trigger) and storage queue? [Answered]Here is what I'm looking at. https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindi❔ empty string not being recognized```cs string name = nameHolder.text; if (String.IsNullOrEmpty(name)) { name = "New Save"; }``` IStreaming a csv file to a console app with minimal api-How?Hey Guys got this methode: ``` public string MakeHttpCall() { var watch = new Stopwat❔ for is toughOn sports day, the students compete in the high jump. Write a program that accepts as input the nam❔ EF Core nullability vs API nullability behaviorIn EF Core, nullability of properties is deduced from the nullability of their type. In API's howeve