Dusty
❔ Markdown RegEx substituation
Hey, I need some help making a RegEx to convert StackExchange markdown to discord or rather CommonMark markdown.
From:
To:
This is what I tried so far however I can't get it to work: https://regex101.com/r/mxeeiW/1
17 replies
✅ Refit / RestLess API SDK Structure
Hey!
How do I structure an SDK for my API?
Let's say I have 2 resources: Users and Groups.
I could use Refit or RestLess to create an interface which wraps the CRUD operations on both resources.
However if I add more resources (which I do have) to the interface it gets messy.
Is there a way to structure my API SDK like this?
Where
IMyUsersApi
and IMyGroupsApi
would contain all CRUD operations for their resource.12 replies
✅ Set TimeZone for request duration in ASP.NET Core
Hey,
I am generating PDFs on the server with
DateTime
objects. The problem is that my clients come from several different time zones and want the PDF to be generated in their own time zone.
Question:
How do I convert the DateTime
object to a string using the time zone of the client?
Should I just send the browsers time zone as query parameter or are there better approaches?8 replies
✅ Soft Deletions with EF Core
Hey,
instead of deleting the entry from the DB directly I am setting a
IsDeleted
property to true.
Generic saving etc. works already.
Now to my problem:
I don't want to call .Where(x => !x.IsDeleted)
every time I query an entity as it's very error prone.
Is there any good design pattern you'd recommend to add this to (almost) every call?
What I've tried so far are global query filters.
The issue with that is that several entities depend on the entity that has this global query filter. If I remove the global query filter it works fine but then I do remove my tenant logic.
So global query filters are not an option.102 replies
✅ Is managed pointer (ref) or raw pointer (void*) null?
How can I check if a managed pointer or raw pointer points to an already garbage collected address?
```cs
var sample = new Sample();
ref var refToSample = ref Unsafe.AsRef(in sample);
sample = null;
// How to check if sample got garbage collected?
// this is false
bool isNullRef = Unsafe.IsNullRef(ref refToSample);
// How to check if the value the pointer is pointing at is garbage collected?
void* ptr = Unsafe.AsPointer(ref refToSample);
20 replies
❔ Authorization handling in asp.net core
Hey,
in asp.net core you can use Authorization Handlers and Type Filters to authorize a request.
The first one needs a policy defined, the other one a custom attribute to authorize a request.
When to use which and what are the pros and cons?
5 replies
Blazor WASM Authentication with separate APIs
I have a Blazor WASM app and an API for that client app. Now I'd like to decouple things and extract the authentication layer into it's own project an API.
So I'd have 4 projects (in reality there're also Domain, Infrastructre etc. projects but for the sake of this example I wanna keep it simple):
- MyProject.BlazorClient
- MyProject.HostApi
- MyProject.Shared (would contain Models, DBContext etc.)
- MyProject.Authentication.Api (should basically act like auth0 and manage authentication)
Purpose/use case:
I would like to have a centralized authentication API like
accounts.myproject.tld
which could be used for other services on that domain like service1.myproject.tld
and service2.myproject.tld
without the need of 2 separate authentication providers. So like I said, basically a "self hosted auth0".
Questions:
1. Are there any examples/tutorials/references of this available? Can't seem to find any and I don't want to reinvent the wheel 😅
2. How can I secure my HostApi with the authentication server?
3. How can I implement authentication with this pattern in blazor?
Do I need to configure the Blazor WASM app to use one API for authentication and another one for data retrieval? If so, how?5 replies
TaskCompletionSource.SetResult() executes on the same thread as the waiting one [Answered]
Hey, as the title already says I've found a deadlock in my code and would like to understand it.
To give you an example:
So why is the awaited method continuing on the thread that called
TrySetResult
?29 replies
Generating random numbers (int32) [Answered]
As you may know
Guid.NewGuid()
returns a 128bit random "number" which is very unlikely to get duplicates of.
I need the same behaviour for 32 bit numbers, what's the best way to achieve that? To just use plain old Random#Next()
? Or use Guid#GetHashCode()
?33 replies
EF Core + SQLite order by decimal value [Answered]
Hey I tried to sort a query via a decimal column but I get this exception:
System.NotSupportedException: SQLite does not support expressions of type 'decimal' in ORDER BY clauses. Convert the values to a supported type, or use LINQ to Objects to order the results on the client side.
I searched a bit an people were speaking about using custom collations. Sadly I haven't found anything else about this yet.
I also tried client evaluation but this just takes too long as my table has several million entries :/
Any ideas on this?4 replies
License Key System
Hey, how would you implement a licensing system?
I basically need those 3 things:
- Online key validation (e.g. HTTP endpoint)
- Offline key validation fallback
- Blacklisting license keys
I know that this doesn't protect piracy in any way but I don't need that anyway.
The basic license check control flow would be the following:
1. Startup
2. Check license key
3. Continue startup or terminate app
I know that IdentityServer uses some kind of licensing system aswell but looking at the source it kinda looks quite complicated.
I also found this library: https://github.com/appsoftwareltd/dotnet-licence-key-generator
Not sure if this is good though.
Tl;dr:
Is there already a library which fullfills my goals and/or how would I implement offline license validation?
2 replies