Core
Explore posts from servers✅ Serialized enum starts with uppercase / camel case is ignored
Hello,
I am using the newer source generated enum serializer (introduced in .NET 8), but for some reason the serialized string starts with uppercase instead of lowercase. https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation#source-generation-support-in-aspnet-core
I even tried another configuration, but it had the same outcome
4 replies
Static class or regular class with interface?
Hello,
I've been building a QR code generator for a while. It's a simple method call
QrCodeGenerator.Generate("data", options)
.
It is a static method/class, I was wondering if it would be better to supply the class trough an interface, making it available trough DI. Suppose it's going to be a nuget package, would it make a difference if it was supplied trough DI, instead of a static class?25 replies
✅ Downloading file with HttpClient does not work
Hello,
Everywhere it is advisable to use
HttpClient
for downloading larger files.
For some reason it only downloads a little chunk of a larger file, and that's it. How should I even determine what the problem is?
The url is fine, I am able to download the file trough the browser
11 replies
SemaphoreSlim wait without creating a critical section
Hello,
I don't want to have a critical section, instead I should have a section where all threads are blocked until the semaphore is released. When it is released, all threads should start executing the section. For this
semaphore.Wait()
is not good, because threads will execute the section one by one.
The outcome should be: No critical section, just blocking for all threads.
Probably some other object is needed for this use case, but what is that?3 replies
✅ Disposable class level property
Hello
If there is a singleton service that uses a disposable class level property, should the service implement IDisposable as well?
Also, wouldn't the property be disposed automatically upon application shutdown, only if it implements IDisposable?
8 replies
✅ .NET 8 enum to string serialization throws an exception
Hello,
Following the docs, a custom
JsonSerializerContext
is applied on the controllers, yet an exception is thrown.
The exception:
I have followed the docs:
https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation#combine-source-generators
https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation#blanket-policy21 replies
✅ Storing user related data when using an auth provider
Hello,
When using an auth provider, all the user data, like ID, email, etc. is stored and managed by the provider. Regarding that, do I need to store the user data in my SQL database and make relation based on that?
Or would it be better to simply add an extra userId column to tables where needed and leave it be? (without any relationship)
13 replies
✅ NodaTime JSON Serialization
Hello,
.NET will parse any date format to
DateTime
or DateTimeOffset
, but what happens if I give NodaTime control over the serialization?
Assuming I accept an Instant
in the DTO and a request comes in, but the format is not ISO-8601
, will it be able to convert any type of date like .NET does, or will it only work with strict types?
From the docs:
21 replies
✅ Background jobs, choosing the right library
Hello,
I need to implement a scheduled job that will be periodically executed.
Why are there so many libraries: Hangfire, Quartz, Coravel? Even .NET offeres the
BackgroundService
out of the box.
How do I choose the right library? Literally every one of them gets the job done...16 replies
Is there a method that throws an exception if a config value is not present in appsettings?
Hello,
Getting configuration values from
appsettings.json
is done via calling builder.Configuration["name"]
. This way few of my services might get a null property, without throwing error before build.
Is there an existing method that will throw an exception if the config value is null
?12 replies
✅ Azure key vault with microservices
Hello,
Right now I have 2 microservice, they communicate with RabbitMq, so the credentials are the same.
Would it be more reasonable to have 2 key vaults storing the same secrets, one vault per each microservice, or create an extra vault for shared secrets?
2 vault, 1 per each microservice
or
3 vault, 1 per each microservice + a shared one?19 replies
✅ EF: how to structure same EF select query with no tracking?
Hello,
I need the exact same select query with and without tracking. Should I implement it in 2 separate methods or a single method with a
bool
parameter that would determine if the query will use tracking or not (e.g. SelectSomething(enableTracking = true)
)?12 replies
✅ EF Best way to do UPDATE on entity
Hello,
EF by default tracks entities. That means, if a property of an entity is modified,
SaveChanges()
will do the update.
Now, I set new values for the properties in the business logic layer, and the repository layer is responsible for any DB operation.
My current method looks like this.... Is there a clearer approach or leave this as it is?
24 replies