Live data from Hacker News

.NET 5.0

devblogs.microsoft.com

271–280 of 466 posts

Re: .NET 5.0

#271
post #29

So, on the plus side with the new .net, I recently made a .net core web app on Linux, and generally it's been pretty easy. I'm also impressed at just how fast asp.net core is compared to asp.net, the time it takes to open your site in debug mode has dropped dramatically, from what used to be 1/2 minute in asp.net to a few seconds in .net core. On the bad side? Mainly the asp.net core team and their push for Dependenc…

I found Go to be a really nice replacement for C#. It has the static typing and garbage collection, but you also get a self-contained binary executing without the requirement of an external runtime environment. I also discovered that I don't miss classes at all.

Go seems nice, but don’t you think writing business logic feels very tedious compared to C#? Generics and linq speed development time up for me significantly.

Re: .NET 5.0

#272

Earlier quoted context omitted.

I agree. The first thing I always do is make a custom Settings class which just loads settings via good old `Environment.GetEnvironmentVariable`. Super simple and never failed me. Bonus Points, by loading all settings at once into strongly typed properties at startup, it will fail fast if a setting is missing, which to me is a benefit. But I still pass this class via DI to the controllers for testability reasons. If…

> make a custom Settings class class which just loads settings via good old `Environment.GetEnvironmentVariable Why would you prefer that, to the the built-in classes to load settings via good old environment variables, among other sources? Which do you think new people coming to your team would prefer to see?

Because the morass that is HostSetting/HostedServices/etc and friends is a confusing tangle of dependencies (some unspecified) bizarre calls that you've missed and general confusion.

I seriously don't understand how MS managed to make loading some configs so outrageously confusing.

Every time I have to write in .net and I'm forced to go down this path, I've got to go back to the one project where it worked, and copy code across and install dependencies until the whole thing decides it's finally happy.

Re: .NET 5.0

#273

Earlier quoted context omitted.

To me it's just so pointless, here's an example: using Microsoft.Extensions.Configuration; //extra line using Microsoft.Extensions.Options; //extra line public class AdminController : Controller { IOptions settings; //extra line public AdminController(IOptions settings) //extra code { this.settings = settings; //extra line } public void RandomMethod() { var a = settings.Value.FinallyMySetting; // 5 extra lines to acc…

Apart from needing two namespaces, this does look reasonable to me. I'm not sure how you could make constructor-based dependency injection easier without making it less obvious what is happening. And most of the additional lines are stuff your editor can do for you, even in VS Code you can automatically generate the field and assignment and the imports after just typing the constructor parameter. ASP.NET Core does pu…

> ASP.NET Core does push you strongly towards dependency injection, but it does not force you at all to use it.

Their own documentation for making queries against SQL Server doesn't provide examples of how to do it that aren't using DI. "Just inject it" it just says. Thanks .net, super helpful. Maybe the docs are there, but I couldn't find them at all when I went looking.

Re: .NET 5.0

#274

Earlier quoted context omitted.

> My biggest bugbear is the way you access your config, which is an absolute and utter kafka-esque mess. Because someone at MS was drinking the DI kool-aid you have to add a minimum of 5 lines of code to any class you want to access config values in I'm not sure if maybe you're referring to the Options stuff? The way I do it is pretty simple. 1. Create a POCO that represents your config. You can have properties for b…

For other people who are curious POCO stands for "Plain Old CLR Object" So I think just a basic uninhereted object.

Apologies, I usually remember to expand acronyms!

Re: .NET 5.0

#275
post #244

Earlier quoted context omitted.

I can get behind the DI dislike, but how are callbacks and promises in nodejs better than async in .NET?

If you're writing modern nodeJS you're probably not using callbacks or promises (directly) anymore (or using promises a lot less than you used to - Promise.all and Promise.allSettled is about it for me, and that's not that often). The async/await syntax is where it's at. Honestly it's a massive improvement over promises, which I hated reasoning about almost as much as callbacks :)

And ... C# _invented_ the async/await syntax. Node, Rust, etc., were all inspired by what C# did.

Re: .NET 5.0

#276
post #129

Earlier quoted context omitted.

That doesn't work unless you already have the using statements, which you won't have as you haven't added it yet. I just tried it.

you can use property injection when you use something like autofac as the di container.

Cool, so I'll add another dependency and figure out how to use that, to save myself time having to write out MS's convoluted dependency-injected configuration code.

Re: .NET 5.0

#277
post #244

Earlier quoted context omitted.

I can get behind the DI dislike, but how are callbacks and promises in nodejs better than async in .NET?

If you're writing modern nodeJS you're probably not using callbacks or promises (directly) anymore (or using promises a lot less than you used to - Promise.all and Promise.allSettled is about it for me, and that's not that often). The async/await syntax is where it's at. Honestly it's a massive improvement over promises, which I hated reasoning about almost as much as callbacks :)

> If you're writing modern nodeJS you're probably not using callbacks or promises (directly) anymore

I get that some people prefer async/await (I actually find explicit Promises clear enough that I don't have any strong preference, myself), but why wouldn't you be using explicit callbacks, which in my JS experience (mostly frontend, but also fairly modern) are super common outside of promises, which is the only place where I see modern JS replacing exlicit callbacks with a different structure.

Re: .NET 5.0

#278

So, on the plus side with the new .net, I recently made a .net core web app on Linux, and generally it's been pretty easy. I'm also impressed at just how fast asp.net core is compared to asp.net, the time it takes to open your site in debug mode has dropped dramatically, from what used to be 1/2 minute in asp.net to a few seconds in .net core. On the bad side? Mainly the asp.net core team and their push for Dependenc…

> My biggest bugbear is the way you access your config, which is an absolute and utter kafka-esque mess. Because someone at MS was drinking the DI kool-aid you have to add a minimum of 5 lines of code to any class you want to access config values in I'm not sure if maybe you're referring to the Options stuff? The way I do it is pretty simple. 1. Create a POCO that represents your config. You can have properties for b…

Exactly. [Removed due to bad wording].

Re: .NET 5.0

#279

Earlier quoted context omitted.

>I agree. The first thing I always do is make a custom Settings class which just loads settings via good old `Environment.GetEnvironmentVariable`. Super simple and never failed me. The .net core configuration mechanism has a hierarchy of providers it reads from, one of which is environment variables, and strongly typed configuration is supported out of the box, so you're exact use case is supported natively by it.

I am aware of this, but like many other, I find the IOptions a bad abstraction. This blog has similar thoughts: https://rimdev.io/strongly-typed-configuration-settings-in-a... or this blog: https://adamstorr.azurewebsites.net/blog/beyond-basics-aspne... Or simply google 'asp net strongly typed configuration' and notice everyone seems to be reaching similar conclusions and building their own things. Just load the sett…

Do not use Options. Use regular poco bound against Configuration sections like the rest of us :)

Re: .NET 5.0

#280
post #269

Earlier quoted context omitted.

We did the migration off ASP.NET a couple years ago. Our site wasnt that big, but we had some major anti-patterns that we decided to address during the migration. (we had multiple CSPROJs for "Businsess Logic" and "Data Access Layer" that didnt do anything of value, end effect was simpler code an ~70% less LOC) There were a few major design changes that we had to embrace in the migration, mainly the middleware and DI…

Out of curiosity, why is your site using .NET instead of a modern framework in NodeJs or Python?

.NET is a modern web framework
Post reply on HN