Tips and Tricks for Asp.net Core Applications
dusted.codes
dusted.codes
`app.When(env.IsDevelopment(), app.UseDeveloperExceptionPage)`.
Also if you're using EF migrations, then stick with the normal CreateWebHostBuilder() method in Program.cs because it's used to bootstrap the program to run migrations at the command line.
In this example, of "GetSomeCollectionFromSomewhere" returns null rather than an empty collection, it is in error and the situation should be corrected inside that method, not at all of the callers.
Also, why would you do "if (someCollection.Count > 0) foreach(var item in someCollection) { ... }" ?
This is exactly equivalent to "foreach(var item in someCollection) { ... }"
There is some value in skipping the foreach since that calls GetEnumerator() and may allocate, but that's very high-performance scenarios. Using LINQ to convert everything to a list and then using IList<T>.ForEach is definitely not recommended though. MS themselves have said that method was a mistake and that the foreach construct should always be used for iteration.
var someCollection = GetSomeCollectionFromSomewhere();
if (someCollection != null && someCollection.Count > 0) { foreach(var item in someCollection) { // Do stuff } }