Messiah
Messiah
CC#
Created by Messiah on 10/2/2023 in #help
❔ Storing static data
I'm working with lots of static data (best example I can think of are items in a game), would you store this data in a struct, static classes, or what? I'm mainly looking for performance and best practices. How would you implement this? I'd appreciate some keywords I could google as well, not sure what to search for this.
28 replies
CC#
Created by Messiah on 9/26/2023 in #help
❔ Singleton/semaphor EF Core
I need to make sure only one instance of EF Core (db context) runs at once, otherwise if two requests arrive at the same time, they'll both search for the username in the DB, see that they don't exist and try to create them, instead of redirecting the second request to a login logic. How can something like this be accomplished? There's a billion different ways to implement this and I'm not entirely sure which one is the best/simplest for my use case. There's blocking collection, dictionaries, semaphores, semaphoreSlim, queues, concurrentqueues, list goes on.
12 replies
CC#
Created by Messiah on 9/21/2023 in #help
❔ EFCore finding a single entry
I need to find an entry in the database or create if it doesn't exist. I can't see any mistakes in my code, yet when I process many chess matches, when an user exists in multiple matches, EF Core keeps adding multiple entries of this same user. Can you see any mistakes in this code? 4 hours of debugging this 😦
var dbAcc = null;
var playerName =entity.properties.RootElement.GetPropertyOrNull("playerName");

if (!string.IsNullOrEmpty(playerName.ToString()))
queryAccs = queryAccs.Where(e => e.PlayerName== playerName.ToString());

dbAcc = context.Accounts.Find(queryAccs.FirstOrDefault());
if (dbAcc == null)
{
var newAcc = new AccountEntity
{
playerName = playerName.ToString() ?? "error",
};
newAcc.ChessTeams.Add(trackedChessTeam);
context.Accounts.Add(newAcc);
}
else{
if (!dbAcc.ChessTeams.Contains(trackedChessTeam))
dbAcc.ChessTeams.Add(trackedChessTeam);
}
break;
var dbAcc = null;
var playerName =entity.properties.RootElement.GetPropertyOrNull("playerName");

if (!string.IsNullOrEmpty(playerName.ToString()))
queryAccs = queryAccs.Where(e => e.PlayerName== playerName.ToString());

dbAcc = context.Accounts.Find(queryAccs.FirstOrDefault());
if (dbAcc == null)
{
var newAcc = new AccountEntity
{
playerName = playerName.ToString() ?? "error",
};
newAcc.ChessTeams.Add(trackedChessTeam);
context.Accounts.Add(newAcc);
}
else{
if (!dbAcc.ChessTeams.Contains(trackedChessTeam))
dbAcc.ChessTeams.Add(trackedChessTeam);
}
break;
8 replies
CC#
Created by Messiah on 9/14/2023 in #help
❔ Dealing with parallel http requests in an API
I have an API that receives many requests before they've concluded executing in the api. This causes unwanted behaviour such as writing twice to the database with the same PK. What options do I have to fix this? I'm honestly looking for the easiest to implement solution, at this point I don't care about good practices or performance, except for only the ASP.NET controller having to be async (so I can't drop all requests while I process one). I've thought about putting requests in queues or channels, also thought about implementing some kind of lock that doesn't drop incoming requests (if that's a thing). Ideas?
25 replies
CC#
Created by Messiah on 9/11/2023 in #help
❔ OSS/Examples for JSON Deserialization?
I'm working on a mid-sized application that does a lot of json deserialization from third party API responses. Does anyone knows where I could find some OSS projects that use json document/node that I could use as reference for advanced json processing?
18 replies
CC#
Created by Messiah on 7/20/2023 in #help
❔ How do yall do HttpClient tokens?
I have a typed http client factory in ASP.NET that I need an OAuth2 token to be shared amongst this type. Is there a library for helping with this or do I have to code it manually? I'm guessing I can put the token in a memory cache, but how do I add the token to each request? Google-fu told me I could use a middleware, but this would regenerate the token with each request, instead of only when it's needed.
4 replies
CC#
Created by Messiah on 4/13/2023 in #help
❔ [MVC/RazorPages] Why can't I access model data?
If I try printing to console the form data that I've [BindProperty] on the OnPost() method, it comes out empty. Why is that? How do I access this data?
5 replies
CC#
Created by Messiah on 3/16/2023 in #help
❔ Forcing token check
2 replies
CC#
Created by Messiah on 3/14/2023 in #help
❔ Two MS Graph Clients on same application
We all know you can DI graph into the application through AddMicrosoftGraph, but I'm trying to have two graph clients (from different AAD tenants), the docs doesn't explain how to do this. Could someone point me in the right direction?
2 replies
CC#
Created by Messiah on 3/10/2023 in #help
❔ MSAL multiple graph clients
Using MSAL, how do you add two different graph clients to the dependency injection? AddMicrosoftGraph() only seems to support adding 1 client.
2 replies
CC#
Created by Messiah on 3/8/2023 in #help
❔ [RazorPages] Any clues why this Select isn't working?
Index.cshtml.cs
public async Task<IActionResult> OnGet(string qstring)
{
Console.writeline(qstring)
return Page();
}

Index.cshtml
@page "{qstring?}"
<form method="get" asp-page="Index">
<select name="qstring">
<option value="one">one</option>
<option value="two">two</option>
</select>
</form>
Index.cshtml.cs
public async Task<IActionResult> OnGet(string qstring)
{
Console.writeline(qstring)
return Page();
}

Index.cshtml
@page "{qstring?}"
<form method="get" asp-page="Index">
<select name="qstring">
<option value="one">one</option>
<option value="two">two</option>
</select>
</form>
In theory it should print out and refresh the page when I select, but in reality it's not working. What's happening?
6 replies
CC#
Created by Messiah on 2/22/2023 in #help
❔ dotnet start, and profiles
When I run dotnet run, which profile from launchSettings.json is chosen? There are so many ways to set profiles in .net, I'm confused.
6 replies
CC#
Created by Messiah on 2/17/2023 in #help
❔ How do toggle top level statements?
There's no mentions of this on google. How do you enable/disable this in an existing project?
11 replies
CC#
Created by Messiah on 2/1/2023 in #help
❔ Razor pages redirect
How do you make a form redirect to a page, and pass a value to it? My entire application is routed as such: "www.site.com/thepage/thequery". How do I get data from the form and pass to the page it, with the query? I can't get it to work without with the url formatted like that
9 replies
CC#
Created by Messiah on 1/26/2023 in #help
❔ Which libs to use for this kind of application:
Think of the start menu, except it's a circle and it shows up wherever your cursor is. Which c# library would you use for this? Looking for something modern
5 replies
CC#
Created by Messiah on 1/26/2023 in #help
❔ credentials in git
so I been using git locally and in a private repo, and I didn't exclude the account credentials from the repo. But if I add the credentials file to the .ignore, then push and make the repo public, the old file will still show up in the change history, yeah? How do I get rid of the existence of this file entirely?
3 replies
CC#
Created by Messiah on 1/13/2023 in #help
❔ How to properly redirect in Razor Pages?
I'm redirecting w/ variables using: 1. <a asp-page="Stats" asp-route-qurl="@j">button</a> redirects to /Stats page, also sending a string to the page. 2. /Stats page calls a 3rd party API using the string 3. /Stats renders itself using response from 3rd party API But this is causing me to lose my session tokens. Every page is properly DI'd with downstreamWebApi. Do I have to add some attributes to get .AddDownstreamWebApi() to work with every page, or am I just redirecting wrong?
2 replies
CC#
Created by Messiah on 1/13/2023 in #help
❔ Razor pages view
In this snippet
@foreach (var cafe in Model.CompanyCafes)
{
@await Html.PartialAsync("Cafe", cafe, new ViewDataDictionary(this.ViewData) { { "ShowImage", true } });
}
@foreach (var cafe in Model.CompanyCafes)
{
@await Html.PartialAsync("Cafe", cafe, new ViewDataDictionary(this.ViewData) { { "ShowImage", true } });
}
Where does razor pull the Model.CompanyCafes from? The MS docs regarding model binding is a bit confusing as it assumes I know a lot beforehand
22 replies
CC#
Created by Messiah on 1/12/2023 in #help
❔ CallWebApiForUserAsync
I'm doing
List<T>.ForEach(i => {
_downstreamWebApi.CallWebApiForUserAsync(
SERVICE,
options => {
options.RelativePath = i
List<T>.ForEach(i => {
_downstreamWebApi.CallWebApiForUserAsync(
SERVICE,
options => {
options.RelativePath = i
but for some reason it isn't calling the api not even once. How do you go about calling the api with a list?
18 replies
CC#
Created by Messiah on 1/10/2023 in #help
❔ MVC models conflicting names
I'm consuming a big api from azure, and the child model classes I'm building have conflicting names after I paste classes as JSON. Example:
class Cats
{
public int size {get; set; }
public Skills skills {get; set;}
}
class Skills{ string blabla {get; set;}}

//other file
class Dogs
{
public int size {get; set;}
public Skills skills {get; set;}
}
class Skills{ string blabla {get; set;}}
class Cats
{
public int size {get; set; }
public Skills skills {get; set;}
}
class Skills{ string blabla {get; set;}}

//other file
class Dogs
{
public int size {get; set;}
public Skills skills {get; set;}
}
class Skills{ string blabla {get; set;}}
I only need the root node to be public, but it doesn't seem like a good solution to make the child nodes private since i'll need to access them at some point. Is there a way to make child nodes only accessible if I write out the root node name first?
5 replies