Live data from Hacker News

Understanding the .NET ecosystem: The evolution of .NET into .NET 7

andrewlock.net

211–220 of 357 posts

Re: Understanding the .NET ecosystem: The evolution of .NET into .NET 7

#211
post #12

Been using .NET for years now for backend web development after having taken a break from C#. It is such an improvement over the old .NET framework. When I started building my first backend with it, I was surprised how much was included and "just worked". Need to add authentication? Few lines. OAuth? Also built in. Response caching? Yes. ORM? EF Core is pretty good. Need to use env variables to override your JSON con…

I have been having a ridiculous time trying to find out just how to override an appsettings json variable (DBConnection string) with an environment variable. Could not find any good answer. What is the right way?

Configuration is applied in layers. If you’re using the default setup you get the following layers applied in this order:

1. appsettings.json

2. appsettings.{env}.json

3. user secrets (only in Development environment)

4. environment variables

5. command line args

You can full customize the setup if you desire, there are packages to support things like external secret stores. If you Google ‘Asp.Net core configuration” there’s a MS page that goes into great detail on all of this.

Anyway, your env vars must match the name as you’d structure it in a json object, but with the periods replace with double underscores. So ConnectionStrings.MyConnection becomes CONNECTIONSTRINGS__MYCONNECTION, FeatureFlags.Product.EnableNewIdFormat becomes FEATUREFLAGS__PRODUCT__ENABLENEWIDFORMAT, etc.

Re: Understanding the .NET ecosystem: The evolution of .NET into .NET 7

#212

Earlier quoted context omitted.

I have been having a ridiculous time trying to find out just how to override an appsettings json variable (DBConnection string) with an environment variable. Could not find any good answer. What is the right way?

You can have multiple appsettings files and are additive. Eg, you can have appsettings.production.json which only contains an override for the connection string in the base appsettings.json.

I believe GP is asking about using runtime environment variables passed in through the shell or injected when starting a Docker container, i.e. the 12factor.net approach.

Re: Understanding the .NET ecosystem: The evolution of .NET into .NET 7

#213

.NET has been doing a lot of things right. My startup's codebase is nearly all .NET 7: landing page, web app, Windows service, API. The main non-.NET code is vanilla JS in the web app. I've been keeping a close eye on Next.js, which is very well done, but I love how versatile .NET is. With one language, I can write all of the above, and my dependencies are minimal thanks to .NET's rich standard library - a refreshing…

How do the costs of running the .NET 7 codebase compare with running something open? I like .NET a lot, have worked with it a lot in the past. But when I tried my own startup, I picked node instead and don't really regret it. I'm getting back into .NET these days though at a new job again, and .NET 7 will be interesting to dive into. Still not sure I'd want to be that tightly-coupled to Microsoft subscriptions though. I'd tried getting a couple .NET projects off the ground back in the .NET 5 days or whenever .NET Core first became a thing. It was surprisingly expensive to run things in Azure, and to use tools too. So that played a role in me just picking node for my startup even though I'd have preferred to stick with C# and .NET if I could, so I could become an expert in those tools.

But yeah, it's definitely a huge plus to have access to .NET's massive standard library. The documentation is amazing, too. If the costs to run in Azure and to be tightly-coupled with Microsoft rthat way are reasonable for a lean/small startup or self-funded startup, then I may give it a shot again.

Re: Understanding the .NET ecosystem: The evolution of .NET into .NET 7

#214

Earlier quoted context omitted.

"Our app was seamlessly upgraded from .NET 3.5 SP1 to .NET 4.0 and through to .NET 4.8.2. I don't believe you when you say it won't immediately run on .NET 5.0. My PS5 plays PS4 games. Upgrade it today as I'm off to play golf."

> My PS5 plays PS4 games. That sounds like an outlier, though. Typically, consoles were not compatible between generations. PS1 games didn't play on PS2. PS2 games didn't play on PS3. Etc.

The first version of the PS3 had hardware PS2 emulation. I think this was removed in later versions.

Re: Understanding the .NET ecosystem: The evolution of .NET into .NET 7

#215
post #196
post #183

Earlier quoted context omitted.

I stuck to DB-First model + LINQ + SaveChanges() and largely managed to keep out the magic quite successfully for a .NET6 web project last year. Records are fantastic when composing queries. I didn't touch inheritance or any fancy mapping strategies -- one table, one class. The only bit of framework-specific / hidden magic debugging I really had to do was the realization of AsSplitQuery() when creating objects compos…

What is DB-First model ?

There was a specific feature in the .Net Framework version of EF called “database first” that would analyze your existing database and generate an xml file describing it that EF would use to generate models on the fly. It was pretty horrible and thankfully isn’t supported by modern EF Core. However the term database first stuck and it’s really come to refer to any any scenario where you manage your database using a tool other than Entity Framework migrations. Could be a dedicated migration tool, Sql Server database project, whatever. Then you either create EF models to match the tables or use a tool to generate them.

Re: Understanding the .NET ecosystem: The evolution of .NET into .NET 7

#216
post #12

Been using .NET for years now for backend web development after having taken a break from C#. It is such an improvement over the old .NET framework. When I started building my first backend with it, I was surprised how much was included and "just worked". Need to add authentication? Few lines. OAuth? Also built in. Response caching? Yes. ORM? EF Core is pretty good. Need to use env variables to override your JSON con…

> I was surprised how much was included and "just worked". A simple HTTP server? Maybe I'm missing something, but when I needed it I hadn't found one. I believe, the closest it has is System.Net.HttpListener which is a very different thing from your typical Golang's net/http.Server or python's http.server.HTTPServer. I believe at some point they had switched from HTTP.sys to Kestrel, so at least it doesn't need the a…

It sounds like you want minimal APIs: https://learn.microsoft.com/en-us/aspnet/core/tutorials/min-...

If for some reason you don’t want the framework to handle things like routing or request/response deserialization/serialization then you can go bare bones and implement everything via custom middleware: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/m...

Re: Understanding the .NET ecosystem: The evolution of .NET into .NET 7

#217
post #154

Earlier quoted context omitted.

> Get a new job ;) Done :-). > Some products/companies just die, because of bad management that doesn’t react to change Some don't have to because they get paid no matter what.

Sure, but at some point the last sane developer either quits or retires, and then they are completely f*ed.

15 years of management experience. Oversaw the reduction of personnel expenditures by 90%. They'll do fine.

Re: Understanding the .NET ecosystem: The evolution of .NET into .NET 7

#218
post #211

Earlier quoted context omitted.

I have been having a ridiculous time trying to find out just how to override an appsettings json variable (DBConnection string) with an environment variable. Could not find any good answer. What is the right way?

Configuration is applied in layers. If you’re using the default setup you get the following layers applied in this order: 1. appsettings.json 2. appsettings.{env}.json 3. user secrets (only in Development environment) 4. environment variables 5. command line args You can full customize the setup if you desire, there are packages to support things like external secret stores. If you Google ‘Asp.Net core configuration”…

Thank you - I had read that portion of the docs but for whatever reason that part of it just didn’t click. For some reason it made me think I could only use some special subset of env vars that were prefixed with ASPNET_CORE or similar

Re: Understanding the .NET ecosystem: The evolution of .NET into .NET 7

#219
post #71

.NET has been doing a lot of things right. My startup's codebase is nearly all .NET 7: landing page, web app, Windows service, API. The main non-.NET code is vanilla JS in the web app. I've been keeping a close eye on Next.js, which is very well done, but I love how versatile .NET is. With one language, I can write all of the above, and my dependencies are minimal thanks to .NET's rich standard library - a refreshing…

Fortunately NextJS and .Net isn’t strictly an either/or proposition. I’ve moved most of my new front-end development to NextJS at this point and use C# for most everything behind it.

A few years ago, the authentication/authorization story was quite tough to configure in this setup. Did things change recently?

Re: Understanding the .NET ecosystem: The evolution of .NET into .NET 7

#220
post #72

Odd question maybe, my company uses C# and I've been picking up more backend responsibilities. However, I'm a Linux and Neovim user. I do have Windows and Visual Studio available but I just find it awkward. Is anyone here having success with Linux and Neovim for C#? Even trying to learn more about the language is awkward as so many resources go straight into VS.

Rider is pretty much the only decent option for me, if Linux is a requirement. However not even Rider supports .NET Hot Reloading (Edit and Continue), because Microsoft hasn't implemented runtime support for it in Linux. Doing so would probably work against their vested interest in rolling in Visual Studio subscriptions. Yet EnC is a significant timesaver for my projects, to the point where I find it hard to work without it.

https://github.com/dotnet/runtime/issues/12409

So the most efficient C# development solution for me is going back to Windows and Visual Studio. As they want it to be.

Post reply on HN