Live data from Hacker News

.NET 5.0

devblogs.microsoft.com

341–350 of 466 posts

Re: .NET 5.0

#341

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…

The interface just doesn't bother me. I make reasonably good use of the hierarchical config providers including some custom ones. Plus it supports actually being able to live update the config values.

Meh, seems like just an interface to me.

Re: .NET 5.0

#342
post #327
post #294

Earlier quoted context omitted.

In the .NET context, browser-targeted deployments can have a minimal download overhead of around 2 MB, which is a far cry from 50 MB. How? Blazor. For details, see https://blog.ndepend.com/blazor-internals-you-need-to-know .

That's 2Mb front-end which is quite heavy.

How 2 MB could be considered heavy, when visiting most websites results in much larger sizes of downloaded resources?

Re: .NET 5.0

#343

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…

> the really poor async code

Very curious. Why do you think it is poor ? Are you comparing it against other languages or frameworks?

Re: .NET 5.0

#344

Earlier quoted context omitted.

I'm going to have to disagree here. Having a settings object is much easier then appsettings.Test.json The .json is for running the application locally. A unit test should be able to cover if a setting has value 'a, b or c', which is much easier with a regular object.

Making software harder to read, write, and maintain in the name of making unit tests easier to read, write, and maintain is putting the cart in front of the horse.

Indeed it would be but making unit tests easier to read, write, and maintain should force you to make the application easier to write and maintain. I agree that readability can suffer somewhat if you’re not careful though.

Re: .NET 5.0

#345

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…

Also, I find DI to be very useful. I dont know about small projects, but in any reasonable size projects, having a DI container is a god send. Easy to setup and use.

Re: .NET 5.0

#346

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…

Options are a very misunderstood abstraction that we have done a poor job explaining. Those blog posts are simplistic and don't explain what you gain and lose by using the options abstraction.

Re: .NET 5.0

#347
post #340

Earlier quoted context omitted.

The DI in .NET is really powerful and feels intuitive once you play around with it in a few different projects. We have almost 100 services injected into .NET Core DI and it always feels very stable and manageable. For us, we cheated a little bit on many services and just take a dependency on IServiceProvider to get at other services at runtime. This allows for any service to talk to any other service without worryin…

Thank you very much for sharing your DI experience. What is wrong with using IServiceProvider dependency? What is CTOR (hierarchy)?

CTOR heirarchy - Constructor Hierarchy.

You have to have your constructors such that the ones needing a lot of services and in-turn those services needing a lot of other services need to be added to the service container and ensured to be instantiable.

Essentially, you build a tree of your services and have to ensure that all your constructors have objects that can be instantiated or managed by the DI system.

Re: .NET 5.0

#348

Earlier quoted context omitted.

>and you're in for an even bigger nightmare if you want to separate business logic and web code into two projects (which is a pretty common design). I've given up with the config DI and just assign them all to static variables. So you have static variable in web project and then add reference to web project to obtain that config? Do I get that right? I never felt like config DI was a problem once you did all the stuf…

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…

> When you compare that to what any other framework does

Can you show me what that looks like?

Re: .NET 5.0

#349
post #323

Earlier quoted context omitted.

If you want to see how much code you get 'for free' by defining a record that you used to have to do manually, check out the generated C# here (structural equality, GetHashCode, Deconstruct, cloning for 'with', pretty printing, etc) https://sharplab.io/#v2:EYLgtghgzgLgpgJwDQBMQGoA+BYAUANwgQAI...

Aren't records meant to be immutable? I don't understand why properties have setters in the generated definition of the record. I'm missing something.

Constructor-defined properties of records are implemented using auto-implemented properties with the new init keyword, so:

    public int MyProp { get; init; }
instead of

    public int MyProp { get; set; }
Apparently those are implemented using readonly backing fields while still retaining property setters.

Re: .NET 5.0

#350

Earlier quoted context omitted.

Authentication is in the request pipeline, so it makes sense that it's async if you're talking to some sort of storage engine. We're using the async APIs to pull user/client app information from our database. Why would we want that to be synchronous?

> Why would we want that to be synchronous? Authentication is blocked by accessing storage. You cannot proceed until the storage read operation is completed. There is no parallel work to be accomplished here. This isn't UI code. There's no event loop. Why would you want this to be asynchronous? This seems like async as a dogma, rather than as a tool to accomplish something specific.

There is sort of an event loop: the .NET Threadpool. It is used by async by default. It will by default quickly create an number of threads equal to the number of CPU cores, but then slowly increase it beyond that. If you are blocking in a threadpool thread, the work item queue will back up. This is called threadpool starvation.

Some articles:

https://docs.microsoft.com/en-us/archive/blogs/vancem/diagno...

https://github.com/Microsoft/vs-threading/blob/master/doc/th...

Post reply on HN