Thinker
✅ Authenticating using OAuth
Does anyone have any resources on authenticating using OAuth? I wanna interact with the Google Workspaces APIs which require OAuth authentication, but I have no idea how to properly set it up. I have the OAuth2 client secret and ID set up, I'm just unsure of how to use it.
58 replies
✅ Implementing Tarjan's strongly connected components algorithm
So I'm trying to implement Tarjan's strongly connected components algorithm, an algorithm for generating strongly connected components from a graph. I already have a graph (a list of nodes), and I've tried to implement the algo, but it does not work as intended. And yes I'm using a struct to keep track of data associated with the nodes, sue me. https://paste.mod.gg/odfzzxyybahk/0
7 replies
✅ Copy files generated by command to build output
During a build, I want to run a command to build a Vue project which outputs its files to a folder, then copy the files from that folder to a
wwwroot
folder in the project's build output. How would I do this? I know I can use Exec
to run the command which works fine, but I don't know how I would copy the files properly while preserving the subfolder structure.57 replies
✅ What's the point of MediatR?
I haven't done a lot of web/API dev, so this might just be because I've never been in a situation where I've actually needed it, but what is the point of MediatR? I don't really understand it too well, so if someone could give me a rundown, that would be incredible.
128 replies
❔ Default command in System.CommandLine
I'm using System.CommandLine for a little CLI, and I want two commands:
compile
and run
. What I want is for the user to be able to just do myapp path/to/some.file
which would invoke compile
by default, but also be able to do myapp run path/to/some.file
, in a similar vein to how dotnet path/to/some.file
is just dotnet exec path/to/some.file
. How do you do this?25 replies
✅ Thread-safe list
I'm trying to turn a piece of code which just calls a list of tasks asynchronous. Each of these tasks writes to a
List<T>
passed to all the tasks. I'm using Task.WhenAll
to run all the tasks in parallel, however I'm unsure of whether using a regular List<T>
is fine or if I should be using something else.3 replies
✅ Allowing option of using dependency injection
I'm working on a small-ish project, mostly for personal use. I have a 'core' type called
ILazyGenerator
and a corresponding ILazyGeneratorBuilder
type, both with 'default' concrete implementations in the same project. These default concrete types or interface don't inherently provide any support for dependency injection, but in the slim case that someone else who maybe eventually possibly perhaps is going to use my library wants dependency injection, I might want to support that. However, I really want to keep this initial project relatively small and simple, and not have to bring in huge packages like MS.Ext.DI. So there are two possibilities I'm considering: either I have the interfaces a mess of generics which provide support for generic context objects everywhere, or I just bite the bullet and include standard support for DI using MS.Ext.DI in the base library. Obviously the latter is easily the simpler of the two, however I still would like some feedback.12 replies
❔ ✅ Is middleware considered a pattern?
I'm working on a little toy project, and I want to implement a kind of "middleware" into it. However, other than ASP.NET, I'm having a hard time finding resources about implementing middleware as a pattern. Is middleware considered a "pattern", or is it just something that exists in ASP.NET and not really anywhere else else? Are there any decent resources about implementing it into applications?
20 replies
✅ 0-1 sine wave
Just a super general math question. If I want a sine wave which has a period of 1 and an amplitude of 1 which goes between 0 and 1, what would be the most concise way to write that? I.e.
f(0) = 0
, f(0.5) = 1
, f(1) = 0
, as a sine wave.35 replies
❔ Best way to display a continually updating list of messages
This is a component in a Blazor WASM chat app I'm developing which job is to display a list of messages. However I'm wondering whether this is an alright-ish way to go about keeping a continually updating list of messages, because to me it feels a bit iffy. Especially the fact I have this
Remove
call which has to iterate through all the messages to remove it. I don't know how well this would scale or whether there is a better approach.32 replies
✅ Is System.Half ever used?
Just wondering, what's the point of
System.Half
? It doesn't even have an alias unlike most of the other numeric types. I assume it's in the same boat as Int128
where it's a numeric type in System
but doesn't have the runtime support of the other numeric types?12 replies
✅ Best practice when using HttpClient in a class
I have a class which essentially acts as a wrapper over an HttpClient as an abstraction for a web API. This class has a field
private readonly HttpClient client;
which is currently set through the constructor of the class, where I'm just kind of expecting the consuming code to have configured the base address and any other configuration in regards to the client itself. However, I don't know if this is considered good practice, or if there's some other way I'm not aware of. This class should also be usable with DI, so I don't know if I instead should have an IHttpClientFactory in the constructor or something instead.116 replies
✅ Is it worth having an abstractions "layer" for a web API?
I'm working on a website project using an ASP.NET web API for the backend and Blazor WASM for the frontend.
Since I'll one way or another need to call my web API from the Blazor project through an
HttpClient
, would it be worth abstracting this into its own project with classes which act as almost "front-ends" for the API itself with strongly typed methods corresponding to the API endpoints? Or would it just be more straightforward to just call the API through a raw HttpClient
in the Blazor project?7 replies
✅ Regex which matches strings containing things other than specific patterns
This is probably a very weird question (and also isn't strictly related to C#). I need a regex which matches strings which contain anything but a specific set of patterns. For instance, a string should match if it contains anything but substrings which match either
<\d{5}>
or \s+
. I don't even know if this is possible, just wanna ask.60 replies
✅ Lazily combine sets
I'm not expecting this to be possible but just asking in case.
Is there any way to lazily combine sets, like if you did
xs.Concat(ys)
with regular enumerables? What I would be looking for is a way to take two IReadOnlySet<T>
s and combine them in a way that you get back another IReadOnlySet<T>
which is a combination of both of them, but which isn't evaluated immediately but rather lazily.15 replies
✅ Error when including a project reference in a Blazor WASM project
I'm getting an error
There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'browser-wasm'.
only when including a ProjectReference
to another project in my solution in a Blazor WASM project. Both projects are targeting net7.0
. Do I have to do something special to get the project reference to work properly with WASM or something?23 replies