News for hackers. Stuff that matters.
Re:Tips and Tricks for Asp.net Core Applications by samuelrodriguez on Saturday March 02, 2019 @04:28AM (#19288440)
Some good tips there. The `When` extension method is really nice:

`app.When(env.IsDevelopment(), app.UseDeveloperExceptionPage)`.

Re:Tips and Tricks for Asp.net Core Applications by manigandham on Wednesday March 06, 2019 @11:50AM (#19320332)
That 'finally' clause might not run to flush Serilog at the end. The webhost will listen to several exit events but some like window close, cancel key, some exceptions, and others will close the program at soon as the event handler returns. This is why the webhost registers a ManualResetEvent to block the event handler until the Program.Main() is finished running.

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.

Re:Tips and Tricks for Asp.net Core Applications by SideburnsOfDoom on Saturday March 02, 2019 @01:39PM (#19290453)
Tip 12: "Working with Null Collections" has it slightly wrong: always return empty colletions, not null ones. There are already helpers for that: https://docs.microsoft.com/en-us/dotnet/api/system.linq.enum...

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) { ... }"

Re:Tips and Tricks for Asp.net Core Applications by manigandham on Saturday March 02, 2019 @05:42PM (#19291582)
Agreed that upstream methods should always return a collection and not null.

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.

Re:Tips and Tricks for Asp.net Core Applications by mandeepj on Saturday March 02, 2019 @07:10PM (#19291929)
I think you had misread it. Author was commenting on other developers who have written following code - "How often do .NET developers write something like this:". And, was not promoting this approach.

var someCollection = GetSomeCollectionFromSomewhere();

if (someCollection != null && someCollection.Count > 0) { foreach(var item in someCollection) { // Do stuff } }

Re:Tips and Tricks for Asp.net Core Applications by restlessmedia on Saturday March 02, 2019 @08:18AM (#19289114)
This is brilliant, really well written as well.
Re:Tips and Tricks for Asp.net Core Applications by Mirioron on Saturday March 02, 2019 @09:29AM (#19289392)
Is tip #12 actually an improvement? I think I would prefer to read the original code than that so specific construct.