becquerel
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
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
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
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