becquerel
becquerel
CC#
Created by jojomueller05 on 1/8/2025 in #help
Worker service recommended folder structure / namespaces
i've seen tests which make assertions based on the log messages a class made - extremely useless and annoying lol
18 replies
CC#
Created by jojomueller05 on 1/8/2025 in #help
Worker service recommended folder structure / namespaces
also, tests should measure the visible output of a system. they shouldn't try to peer inside a system to examine its internals
18 replies
CC#
Created by jojomueller05 on 1/8/2025 in #help
Worker service recommended folder structure / namespaces
i would say the biggest things are - for unit tests, avoid non-determinism. if you use randomness, make it so you can seed it. don't use DateTime.Now - inject an ISystemClock instead. I/O is inherently non-deterministic, so either avoid doing I/O in your business code (best option) or mock it out (easier) - for integration tests, look into Testcontainers. it's far easier to just spin up a real database in a container than to try to make a fake database or mock it out - get your tests running in a continuous integration pipeline as a priority. otherwise you will forget to run them - generally, prefer to use dependency injection for your classes. it makes life a lot, lot easier. by that token, avoid using static methods or extension methods which do complex things, as you can't mock them out
18 replies
CC#
Created by jojomueller05 on 1/8/2025 in #help
Worker service recommended folder structure / namespaces
very big topic
18 replies
CC#
Created by jojomueller05 on 1/8/2025 in #help
Worker service recommended folder structure / namespaces
good resources on how to write testable code in C#?
18 replies
CC#
Created by jojomueller05 on 1/8/2025 in #help
Worker service recommended folder structure / namespaces
e.g. if you need to change your newsletter email feature, you don't want to have to search around five different 'layers' to find all the relevant code
18 replies
CC#
Created by jojomueller05 on 1/8/2025 in #help
Worker service recommended folder structure / namespaces
the motivation for this is that code usually changes based on feature, and code that changes together should live together
18 replies
CC#
Created by jojomueller05 on 1/8/2025 in #help
Worker service recommended folder structure / namespaces
organising things based by if it's a filewriter or about the database goes against this
18 replies
CC#
Created by jojomueller05 on 1/8/2025 in #help
Worker service recommended folder structure / namespaces
i.e. 'all the code for signing up new users goes into this folder', 'all the code for sending newsletter emails out goes into this folder'
18 replies
CC#
Created by jojomueller05 on 1/8/2025 in #help
Worker service recommended folder structure / namespaces
organise your code based on the categorisations real humans would care about, not programmers
18 replies
CC#
Created by jojomueller05 on 1/8/2025 in #help
Worker service recommended folder structure / namespaces
structured by Entity (e.g. FileWriter/, Customer/, DB/, ...),
no, structured by feature - that's an important distinction
18 replies
CC#
Created by sl8er on 1/9/2025 in #help
Overriding appsettings.json section with environment variable
Yeah, I feel like this is a bit of an x/y problem. why do you want to override a big json object with environment variables?
25 replies
CC#
Created by sl8er on 1/9/2025 in #help
Overriding appsettings.json section with environment variable
e.g. export TENANTS__ByCode = ["foo", "bar"]
25 replies
CC#
Created by sl8er on 1/9/2025 in #help
Overriding appsettings.json section with environment variable
I don't think what you want is supported. My understanding is IConfiguration takes an environment variable as representing a single atom of configuration, not as something that can potentially represent an entire configuration section. If you set the env var to a JSON string, then IConfiguration will consider it as just a string. I think the 'right' way to do this would be to set up multiple environment variables to override each property of the structure.
25 replies
CC#
Created by jojomueller05 on 1/8/2025 in #help
Worker service recommended folder structure / namespaces
Generally I find it more worthwhile to get integration tests set up that to try and abstract away my database for the sake of unit tests
18 replies
CC#
Created by jojomueller05 on 1/8/2025 in #help
Worker service recommended folder structure / namespaces
Your last line makes me think you are interested in making sure your code is testable, but that is a bit of a big topic separate to how you organise your code.
18 replies
CC#
Created by jojomueller05 on 1/8/2025 in #help
Worker service recommended folder structure / namespaces
For folder structure specifically, feature-based organisation is becoming more popular these days. So all your types related to (say) UserOrders would go in one folder, regardless of if they're models, services, repositories, etc.
18 replies
CC#
Created by jojomueller05 on 1/8/2025 in #help
Worker service recommended folder structure / namespaces
For this reason I usually have the worker in one project and then all the platform-agnostic code in a separate project it references.
18 replies
CC#
Created by jojomueller05 on 1/8/2025 in #help
Worker service recommended folder structure / namespaces
MVC and similar patterns are really most concerned about separating your business logic from your 'view', which isn't really present in a worker service. But the similarity is you still want a clear delineation between your 'pure' business code and the stuff which knows it's running in a worker service/console app
18 replies
CC#
Created by restock2009 on 1/5/2025 in #help
Weird bug
It's very hard to tell without knowing what the process is, what the result was, or seeing any of your code
4 replies