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 Dependency Injection and the really poor async code has got to be the most frustrating thing about the whole thing.
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, 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. I still don't get why you'd even want your config injected!
The entire authentication uses async code too, which still has all the normal problems of being hard to debug, silently failing if you invoke it wrong and completely overwhelming the callerstack with a bunch of redundant calls.
Huge disadvantages with absolutely zero performance gains for 95% of programmers.
Having been using express again recently, I'm seriously thinking of ditching the asp.net core stack despite my general preference for statically typed languages. C# is great, but the asp.net core are so obsessed with shoving DI and async down your throat and making you write really unpleasant, boilerplate code. Feels like you're back in 1990 with all the FactoryFactoryFactories.
I'm not sure if maybe you're referring to the Options<T> stuff?
The way I do it is pretty simple.
1. Create a POCO that represents your config. You can have properties for bested configs if you want, e.g. SecurityConfig, MessageBusConfig 2. When the app starts, use a ConfigurationBuilder to build an IConfiguration from whatever Co fig sources you want - typically JSON files and env vars 3. Bind the IConfiguration to your POCO 4. Configure both IConfiguration and the POCO as singletons
Now you can inject the POCO config object wherever you want it, or the IConfiguration should you need it. I feel like this is simple, and works well for dev, test and prod.
The options stuff is a car crash.
On my last project, I just assigned the configs to a static class that's available everywhere and the code was just simply much cleaner.
You really don't - just inject your populated config object where you need it.
This is precisely why I jumped ship 5 years ago to Go.
Plenty of other people piping up saying they also find this bad abstraction obnoxious, sorry you can't empathise and understand we all have difference preferences.
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 you are using ASP Net, just do things the asp-net way for the sake of other people who have to inherit the code.
Outside of AspNet I never use any automatic DI.
This feature is added in the `config.AddEnvironmentVariables()` line, which is already included in the default host builder. The latest releases use very good conventions and include a lot of the typical functionality. I recommend reading the docs to avoid redoing what's already there: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/co...
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.
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 setting yourself and register it as a singleton.
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?
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.
appsettings.Test.json
Voila, different settings!
I've said elsewhere, the DEFAULT should be super simple, really, really, really easy to use. No thought, no effort, just use it.
If you want to go all crazy and start injecting values into your config in your unit tests, great to have that option, you should have that option. But you're the one who should be scrabbling around writing tons of extra boilerplate code, not me.
But I just want to set a filepath, that's probably never going to change, but might one day. Or an email address to send a weekly summary email to. Or some settings on paging that the client might change their mind about once and I don't want to have to rebuild the project.
The vast majority of config settings are just cover your ass in case you need to one day change this value. They don't need to be tested.
So it not the "normal" path to need to test config values. It's not the path the vast majority of programmers need.
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.
And of course you can always just access environment variables directly if you want to.
"But wait," you say. "I'll just pass in the thing that provides that data"--and you just reinvented DI, albeit likely poorly.
DI is the removal of complication when it is done correctly. (I have no opinion on whether ASP.NET Core does it correctly.)
There are certain benefits to DI, but this one seems more like a lack of tooling.
I’ve been experiencing the same issue with some Azure SDKs that only expose async methods rather than both async and sync. Frustrating to have to redo 8 caller functions to make a single sdk call.
Though you'll probably hit the `async void return` runtime bug at some point where you accidentally return void from a method you tried to make async but then got bored of rewriting everything, so just whack in a .Wait or .Result() but haven't returned Task and the damn thing fails at runtime with a mysterious error making you curse async even more.
You call .GetAwaiter().GetResult();
and avoid mixing sync and async where at all possible.
This pattern, 'sync-over-async', is to be avoided at all costs, at all times.
You're not going to like it, but the MS recommended way of dealing with this is to make your callstack async.
In all honest - if you're making an ASP net core web app, go all in on async from the start. If you have to mix and match, never go sync-over-async inside an action.
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.
.NET is used by millions of developers. Strong and scalable foundations matter, and performance is an explicit goal with asp.net being one of the fastest web frameworks. Async is a core part of this.
There's very little - if any - overhead that you need to worry about with async code from the language to Visual Studio.
Exactly. So when you await it, that thread that would have but blocked waiting for the I/O instead can be used to service other requests until the I/O has finished.
Concurrency is not parallelism [1].
Some articles:
https://docs.microsoft.com/en-us/archive/blogs/vancem/diagno...
https://github.com/Microsoft/vs-threading/blob/master/doc/th...
Synchronous code locks you into the model of handling one request per thread.
Given the minor overhead (both cognitive and runtime) of a sync/await, I can’t see why you wouldn’t want to do it here.
As regards configuration, all the means you could want for configuration are there. You can access items directly [1], or via strongly typed objects. These all support multiple sources of configuration data, and many means of overriding them.
I generally really don't like environment variables as they expose configured secrets to everything in the same machine / container, but we make use of the standard configuration system's environment variable overrides, but we use akv2k8s.io and thus only expose secrets to the container's entry point application.
[1] public Startup(IConfiguration config) { // injects config store var setting = config["yourConfigKey"] // ... but you now have to convert this from a string for any other datatype }
One curious thing is that Java has elected to use lightweight threads instead of async methods: https://www.javacodegeeks.com/2019/12/project-loom.html
Their arguments are compelling:
- Works with existing debuggers and debugging techniques.
- Stack traces aren't polluted with irrelevant garbage.
- Doesn't create method apartheid, where async and non-async can't "mix".
- Doesn't force library authors to "buy into" the async model.
The nice thing about promise-based async is that it's very easy to map to straight C ABI callbacks, which means that it can be fully cross-language. Green threads are runtime-specific.
With green threads being "free" (you can have millions), it might be reasonable to just block your green thread until the callback arrives.
Should be able to likewise give you a much simpler and understandable config model.
I do this with a lot (most?) web apps, and don't have any issues with it at all - what kind of problems are you seeing?
> I've given up with the config DI and just assign them all to static variables.
Not to be a fanboy, but it's designed in a way where you CAN use all the fancy features. If you want something simpler, you can just do exactly what you did.
This syntax is probably wrong because I'm doing this from memory, you should probably also use the Lazy class or something, and if I were to actually write this code I'd think twice about thread safety -- but if you want simple static access to config values, you can just do this:
public static MyConfigPoco MyConfig {get;set;} = JsonConvert.DeserializeObject<MyConfigPoco>(File.ReadAllLines("appsettings.json")) ;
I'd recommend both node with TypeScript and Rust for backend web development in a statically typed langauge.
But C# lacks an ecosystem compared to Rust? I don't understand that.
I'm not sure whether we're talking about the same thing, but you can publish Self-Contained App (basically your app and framework together) and you don't have to install anything.
In what capacity are you using Go that made it a good replacement for C#? Microservices? If so, which framework are you using?
And also I don't have to fight against the language to do what I want to do ... No classes, no types, no constraints.
Well, do you have all of the bells an whistles that you had with .NET? I mean, you can shrink a .NET API down to pretty much just 1 file if you really want to. The question is if you should.
WebHost.CreateDefaultBuilder().Configure(app => app.Run(c => c.Response.WriteAsync("Hello world!"))).Build().Run();
that's giant, but I don't think that "just" language / environment difference makes this huge difference
The one issue I can see with DI in ASP.NET Core is that it doesn't really do DI correctly. The point of DI is that ultimately, you have complete control over how you build your dependency graph and you shouldn't be forced to use a container at all if you don't want to. With a DI abstraction the developers are basically saying "you can do what you want, as long as it's pretty much exactly what we expect you to do".
This explains this pretty well: https://blog.simpleinjector.org/2016/06/whats-wrong-with-the...
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 stuff that you do at the beginning of the project
using Microsoft.Extensions.Configuration; //extra line
using Microsoft.Extensions.Options; //extra line
public class AdminController : Controller
{
IOptions<Settings> settings; //extra line
public AdminController(IOptions<Settings> settings) //extra code
{
this.settings = settings; //extra line
}
public void RandomMethod()
{
var a = settings.Value.FinallyMySetting; // 5 extra lines to access your config, genius...
}
}
A complete and utter waste of my time to put all those lines in, it's just pointless boilerplate trash, which C# has been getting rid of excellently, all to be undone by whoever wrote Microsoft.Extensions.Configuration. And you have to do it any where you want to get a config value.On top of that, if you want to use it in a console app, you have to add like 5 packages. Yes, FIVE.
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.9" />
Then add this delightful mess just to initialize it: var environmentName = Environment.GetEnvironmentVariable("ENVIRONMENT");
var builder = new ConfigurationBuilder()
.AddJsonFile($"appsettings.json", true, true)
.AddJsonFile($"appsettings.{environmentName}.json", true, true)
.AddEnvironmentVariables();
var configuration = builder.Build();
When you compare that to what any other framework does, it just beggars belief that they though this was a good way of handling config.When I was setting this all up, I obviously hit up SO, and it's clear from many of the (incorrect) answers on SO that people just don't get it. It's too complicated for something that should be super simple.
I get that it's handy to be able to configure all that yourself, but all of that should be default and a single line/package.
ASP.NET Core does push you strongly towards dependency injection, but it does not force you at all to use it.
It is something that annoys me about .NET in general there is just decades of over-engineering cruft and once these practices emerge its difficult to get people to stop doing them. The problem only gets worse as time passes.
It's such convoluted nonsense.
I like C# but sometimes it feels like MS main aim is to make developers miserable.
I don't regard the "ConfigurationBuilder" and following lines as "boilerplate" exactly, since by not using the default HostBuilder and instead including that code, you are making choices.
Specifically, you are choosing to pull in settings from "appsettings.json", "appsettings.{env}.json" and then environment vars, in that order, and specifying that both files are optional and should reload on change.
You can make other choices, with other code.The code is there to "configure the config", i.e. to make those choices.
> it's just pointless boilerplate trash, which C# has been getting rid of excellently
Could you elaborate on how you feel C# avoided this?
From my point of view the only alternative (to DI with constructor injection) is static members somewhere, which does not scale. Maybe property injection, but ugh.
Can you show me what that looks like?
No part of aspnet core is built to run synchronous. Its all async all the way down.
In usual HN fashion, even the most seemingly obviously true points to me are being argued and refuted.
In my experience, the complexity is vastly reduced by not having to implement tricky asynchronous APIs (Task Paralell, thread pools, BackgroundWorker, etc).
I just finished an app that had to shutdown while some async operations were still not finished. Really hard to manage compared to using threads.
It's been said that C# is "Microsoft's Java". That applies not only to the language, but the culture of "enterprise-ism" (insanely excessive abstraction and complexity) that seems to permeate throughout the code.
I worked briefly with Enterprise Java a long time ago, and it brings back much of those memories whenever I have to look for something in a C# codebase.
I've left C# ecosystem 3 years ago because I was done with that as well, but then I landed in a mature Ruby on Rails project and I was crying for .NET "enterprisey" abstractions - once you see the code duplication that comes from the fat models and controllers, you have to grep the codebase and guess what happens in a function because it's in a mixin that assumes property exists in context, tests take forever to rerun because they bootstrap an entire environment and have no mocking. If I had to chose between a bad C# codebase or a bad RoR codebase if it's beyond something very simple I would chose C# one any day of the week - which is what I think C# approach gets you - guarantee that if you follow the conventions your project will scale reasonably well into maintainability and codebase size. You pay for that in initial development speed and pointless verbosity.
Most DI containers are not just injectors, but they also manage life cycles/scopes of objects: singleton/transient/scoped.
Since in web development, a request hitting a controller endpoint is typically short lived and most objects and services are tied to the main request scope, it makes sense that all your objects should live and die when the request is made and completed. What is the cleanest way to manage this life cycle scopes? Dependency Injection. Most of your object/services will be "scoped", with fewer being transient (aka a pool of reusable objects) and the fewest being singletons that will survive individual requests.
A second side effect of DI, it forces you to code by convention. Conventions make maintaining the code 6 months from now a breeze. Want to add a new service? Just let it inherit from an IService and consume it in 10 places, it will auto find/inject your new code. No need to new() up and dispose your service in 10 place.
Do all of this without DI and use only constructors + Dispose(). Good luck! Mercy on the poor soul who has to maintain all that mess.
If you want to go a step further, instead of having 100's of IService and each constructor declaring they each need 10 of them (ILoggerService, IAccountService, IEmailService, IStockService etc etc)... that also becomes very gross in large projects: so to go a step further, use the Mediator pattern. You can either implement your own (super easy) or use the Mediatr nuget package. Then each service becomes much cleaner. Each service then only has 1 method that does work. It also ties in nicely with the Unit of Work pattern.
Why should my IStockService inject the IEmailService when I just want to check stock levels with GetLatestStock() that return an int and does no other work?
Lets say the IStockService has 15 methods to do with stock and 10 dependencies. So on each request where you depend on IStockService, you would also pull in the 10 dependencies and their inner dependencies which may add 1 second to your response time and uses 10mb RAM. But all you wanted to was check stock which takes 10ms and 1mb RAM.
This is exactly the scenario that mediator pattern can help solve. So your 15 methods become 15 individual classes, each pulling in ONLY the dependencies it needs and nothing more. Your file and git commits stay small too which makes everything more digestible (less than 100 lines of code if lucky),
So my favourite setup is DI + Mediatr. Each file/class has only ONE purpose to exist and only one reason to be pulled into a dependency tree, all while DI will manage their life cycles.
Edit: For those downvoting, please go read "Dependency Injection by Mark Seemann" and also read https://docs.microsoft.com/en-us/aspnet/core/performance/per... . Then try to build your own framework from scratch. Do it. Then come crawl back and upvote this comment. I've have a ton of experience with this stuff and have built 2 or 3 custom frameworks. The core trait that keeps everything sane and fast is to keep things simple, keep dependencies low, keep hot paths lean. The easiest way to get to that place is DI + Mediatr and to break some services into their own api's if they get deployed too often. It's that simple.
That imperative lifecycle stuff is a big problem. Is that idiomatic in .net? Ideally, the program creates per-request data and then the garbage collector disposes of it after the end of the request (or earlier if it doesn't need to be retained until the end of the request). If you need to actually call Dispose, short of `using ...`, you have a problem.
> Lets say the IStockService has 15 methods to do with stock and 10 dependencies
Is this idiomatic in .net? It's obvious that that is a problem and that smaller classes/functions are better. Normally, your programming language and environment would let you create smaller classes/functions and call them as necessary. Why is something more complicated required in this context?
DI just hides the problem because such a class is now only 500 lines long instead of 2000 lines, so for some people that is acceptable (not for me though). You don't see any lifecycle code in your classes anymore since the DI container manages it for them.
Remember it is typical to see a business project with 300 classes/tables if the project is about 5 years old and never seen a major refactor/rewrite, and each of those classes gets manipulated in some form from an orchestration point (xManager class or xService class), which in turn might depend on each other or have 10 inner dependencies. To keep things "simple" most guys would just add another method to an existing service where it seems to make the most sense.
I argue against that cause the services become heavier and heavier over time and can do allll sorts of things after 5 years (aka IStockService can now check stock, send email notification, generate invoice, save pdf to disk etc). So I've come to the conclusion its better to have more folders/files to contain handlers, and each handler only has one Execute/Process method, and it's constructor declaring only the minimum amount of dependencies to do it's work. It also encourages ALL your services to do only one thing: you know and can trust that IPdfDiskPersistor only does one thing and doesn't have other weird side effects (like trying to send an email).
If all this is really not clean enough, then maybe an ActorModel framework like Orleans Framework might be better suited, but I haven't been able to convince anyone at work to use it instead of DDD (they are slightly at odds with each other).
Hope that answers some of your questions. If other are reading this, please think twice before you go down the DDD path - it is expensive both in code and time and can easily spiral into a monster (but also well worth it if a good developer have stewardship of it in the long term - keyword being stewardship). Unfortunately teams with high turnover is basically doomed to have a messy/failed project.
Some feel it can be needlessly complex to troubleshoot such a system or gain understanding of it if you weren't one of the original authors.
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 :)
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.
Why not typescript?
But the ASP.NET part feels bloated.
Is there a simpler .NET framework?
Very curious. Why do you think it is poor ? Are you comparing it against other languages or frameworks?
Microsoft has made exceptional strides in terms of performance and compatibility.
The whole vision is what is really impressive, not any individual part.
It is cross-platform, open source, and has almost complete coverage of the old .NET APIs. The new csproj format is vastly superior. The new dotnet CLI is a pleasure to use.
Many of the surrounding libraries like ASP.NET, Kestrel, LINQ, Entity Framework Core, System.Text.Json, etc are best in class.
I look forward to the Linker becoming stable, as this will really help in contexts such as Azure Functions and AWS Lambda.
They already have you programming in their editors (VS/Code) and pushing to their VCS (Github). They're even teaching you the C# type system with TypeScript :) If they can just convince you to use their stack, Azure will win you over from AWS every time.
As a result, I really wanted to adopt .NET earlier this year. But they have some work to do to make the ecosystem approachable to newcomers.
One of the core issues feels so... trite. But experiencing it, I realized how real it really was:
The Names. Microsoft has created a Ninja Warrior obstacle course of proper nouns.
It is comical. It is worthy of parody.
.NET, the CLR, and their relation to C# and F#. ASP.NET, ASP.NET MVC, ASP.NET Web Api, Blazor vs Razor, .NET Core vs .NET Framework vs .NET Standard.
I think I could draw the lines between all those with about 50% accuracy. And I read like 3 books on .NET before diving in.
It's bad off the top when you're trying to figure out which way is up in the ecosystem. It goes from bad to worse when you're looking through docs and Stack Overflow answers.
It was almost never immediately clear if a document I was looking at on Microsoft's own website applied to me or not. That is a cardinal sin of technical documentation.
Ultimately, this meant that .NET Core Web API (or whatever I was using) felt poorly documented.
I'd find myself looking at docs that mention .NET Web API - but I can't remember if that rolls up to .NET Core or Framework -- or both? Am I using MVC? Is Web API a subset of MVC? No clue.
It's definitely a hard problem. Here's to hoping that now that everything is unified, they can work on paving clearer roads into their ecosystem.
Going to have to disagree here.
That might be the case if Azure was not literally a tire-fire. I have been using Azure for work and it's the most frustrating, inconsistent, often-broken, confusing and stress-inducing cloud service that my teammates and I have ever been subjected to. It left such a bad taste that I am quite certain I would flat-out refuse to use it again in the future, or work somewhere that uses it.
Take my advice: just don't use it. It's not worth it. Use AWS, use GCP, use Digital Ocean. Use some random cloud provider. Just don't use Azure.
All of it was painful. There docs were lacking or sent you in circles. The documentation for their firewall product is three-quarters known issues and errors. Azure functions were painful to run locally, good forbid you’re not using Windows. Azure would take ages to attach a node on K8’s. Like, over an hour. It consistently had issues moving Azure disks between nodes in K8s: “can’t mount disk, attached to another host” in comparison AWS will speedily and happily re-attach an EBS disk to a new machine.
Permissions were opaque and distributed across the whole interface.
It silently deprecated keys underneath us, broke a number of services (couldn’t write to attached disks in K8s, couldn’t move them), didn’t inform us that this happened, we only figured it out by trawling through GitHub issues.
Storage Account explorer application breaks/stops consistently.
“Alert but permit” mode on firewalls doesn’t do what it’s supposed to: it will permit, but totally fails to alert you.
Scale sets operate weirdly, I didn’t personally deal with this too much, but my teammates had consistent issues with strange caching issues and more or less machines being spun up than should have.
Until we fixed it, every Azure PoP was health-checking our web app 2-3 times a minute: our logs and servers were being flooded with literally thousands of pointless requests.
If you have an AKS cluster with n machines currently in it, with a minimum and maximum of (n, m) machines, and you want to say, increase the minimum number, you cannot: it will refuse and tell you “the minimum number of nodes must include the current number”, so rather than just automatically adding a new node (a la AWS, and I presume GCP), you have to force the cluster to scale up to the new number of machines by throwing workload at it, then make the change.
AWS has a single Python package called “Boto3”, from which you can do pretty much everything. Microsoft in their infinite wisdom has a separate Python package for every service, and sometimes subset of service. Do you know whether you need the package for Storage Accounts, File Share, Share Accounts, Object Store or whatever else they had? Also, authenticating against these was a pain: sometimes you need a key provided by the service (let’s hope your permissions let you see that), sometimes you need to generate a service principal for your app (unless there is already one? In which case it’s listed in the UI, but nowhere you’ll find it, and certainly not under “service principals”, and you probably won’t have the permissions to see the information you need anyways) and then sometimes you need both!
Azure let us spin up a K8s cluster on a version of 1.18, but then didn’t let us scale the cluster a few weeks later, because apparently that version just didn’t exist, so we should either use 1.17, or update to a newer version of 1.18, but you can’t skip point-releases, so you’re going to have to update everything in your cluster before you can have another node.
AWS is still great, I just happen to like Azure more.
Example of unique services in the GCloud: Spanner, Firestore, BigQuery,...
AWS: Face recognition service and other neat things
Uniquely fucked up in Azure: Functions, Web Apps, Storage, Application Insights (FML!), ... many many more
Nullability analysis was recently added to C# (nullable reference types) but it was in tyepscript first.
The optional nature of the typing can be very useful for the web for sure. From my experience that same flexibility means you can't do as much reflection at runtime as in .NET but I have been for the most part away from typescript for last couple of years, so be interested in any resources around this subject.
See https://www.typescriptlang.org/docs/handbook/advanced-types.... for more. There are a lot of utility types in the standard library that could not be expressed in C# as well.
Reflection is very different. It kind of still exists, but in a very different way.
[1]: .NET on Non-Windows Platforms, a Brief History. https://two-wrongs.com/dotnet-on-non-windows-platforms-brief...
I’m not complaining too much, they are intentionally addressing this fragmentation, but it’s a real mess for newcomers.
Additionally, there seems to be another new way to accomplish this. Normally class properties are accessed via get; and set;
Now we have the ability to use get; and init; which effectively makes the object immutable/read only after initialization. The syntax is just a little cleaner and more obvious to the reader how the property should be used.
C# has really been adding some great features the past few years and is certainly getting more expressive and concise which I appreciate.
Granted, you end up dealing with a bunch of OOP libraries still since .NET is very C#-centered, but the language is pretty good and the integration is painless.
And .NET, like you mentioned, is very C# focused which would become frustrating at times.
https://sharplab.io/#v2:EYLgtghgzgLgpgJwDQBMQGoA+BYAUANwgQAI...
I don't understand why properties have setters in the generated definition of the record. I'm missing something.
It’s also generating code for the main method, which is also a new c# 9 feature
Records generate a lot of code when you compile them, including methods to compare by value.
The boilerplate required to do that in C# without records is extensive and hard to maintain. Even structs, which are supposed to be value objects, are not easy to compare by value.
I'll put it this way: records are important enough that I stopped using C# because it lacked something like records, and now I'm going to pick it up again.
You have to override Equals() and GetHashCode() for starters. Then you also need to make sure you only have getters and no setters (or private setters). In some cases you need to make your empty constructor private and force a specific constructor to be used. If you have multiple constructors it means you will have different invariants which puts you in class land, you are better off with classes then anyway. Also if your immutable objects have many methods..that also puts you in class land.
Just that alone makes it cumbersome.
So a new record type that behaves somewhat like a struct would be perfect. Or the F# way, which is basically perfection.
If you have just 50 immutable classes you have to replicate those 50 lines of boilerplate for each class and make sure it's bug free. It clutters your classes up and it's just plain gross.
It's going to be way better that the platform supports this kind of data structure natively instead of us building out the monstrosity ourselves.
By the way, plenty of the features of C# is basically syntax sugar, gets compiled down to more vebose code anyway. We think we write one or two lines of happy code, but underneath it might get turned into 20 lines. Luckily we mostly don't have to see/deal with it unless you are trying to squeeze your apps performance to the max (or have a nasty bug that cannot be caught by normal means), but at that point it might make more sense to use a lower level language.
https://devblogs.microsoft.com/dotnet/announcing-f-5/#string...
Knew it was coming but still really happy to see this.
Although this is nothing to do with string interpolation, the "typed string interpolation" refer to the F# printf format specifiers.
You could also build such tool separately using FSharp.Compiler.Service (possibly using the analyzer infrastructure for ionide: https://github.com/ionide/FSharp.Analyzers.SDK), AFAIU there will be consolidation of this type of tooling relying on FSharp.Compiler.Service in the future to make this integrated to all F# tooling.
Visual Studio 2019 running as x86 32bits application can't see the local machine as a target for aarch64 applications. When I asked microsoft, the response was to use a x86-64 machine to develop on the same LAN as the aarch64 machine and use remote debugging. So you need two machines to ship a desktop application.
This is bad, and part of the reason there are so few app running natively on the Surface Pro X.
On the Windows side, Visual Studio is still a 32bit application, and as you have pointed out, on ARM, it supports basically nothing but the ancient Win32 C API.
EDIT: Here it is, right on time -- https://www.nag.com/news/first-fortran-compiler-apple-silico...
From the previous version of .Net Core only. They've done absolutely nothing to make migrating from MVC 5 any easier, while proclaiming that this somehow merges .Net Framework and .Net Core. Going from MVC 5 to .Net 5.0 MVC is a complete re-write of the web layer from an empty project upon up (even according to their own article[0]).
I think the poor messaging on .Net 5.0 bugs me more than the actual work required for the mitigation (which hasn't changed significantly). .Net 5.0 is just .NET Core 4 with a fancy new name.
[0] https://docs.microsoft.com/en-us/aspnet/core/migration/mvc?v...
There were a few major design changes that we had to embrace in the migration, mainly the middleware and DI. But we still managed to greatly increase performance, reduce our code footprint and get inline with the future Microsoft's vision for a C# webserver. All in it probably took 2 out of the 10 devs a month to complete the migration, while also addressing critical bugs.
This makes it easier for me to make a case to managers that 4.8->5.0 is an obvious migration to do. Selling 4.8 to core4 would sound scary.
Which is already three major versions ahead off classic .net.
You’re literally complaining about making upgrades past four major releases not being drop-in compatible.
Can you show any other stack which has made such strides to modernise and maintain better compatibility?
> .NET 5.0 is the first release in our .NET unification journey. We built .NET 5.0 to enable a much larger group of developers to migrate their .NET Framework code and apps to .NET 5.0.
Yes, it’s kinda cheating. On the other hand it has been obvious since .Net Core 1.0 that this is where the future is going to be.
All announcements before .Net 5 has been clear on the compatibility issues and preparations required, for a couple of years now.
Whoever haven’t been planning this migration can thank themselves.
Calling what is effectively .Net Core 4.0 for simply “.Net 5.0” is just a way to make it completely obvious, even to those not paying attention, that .Net Framework 4.8 is now superseded, and that the upgrade path is .Net (Core). There’s no other option around the corner. Get with the times. Etc.
If you read a dozen blogs posts about the background for the decisions and are able to hold all that information in your head while you need to make a decision, it is possible to attain clarity for a few moments. But it is not fun.
On the plus side, going back to versioning .Net should help for the next few years to come.
> .NET 5.0 is a current release. That means that it will be supported for three months after .NET 6.0 is released. As a result, we expect to support .NET 5.0 through the middle of February 2022. .NET 6.0 will be an LTS release and will be supported for three years, just like .NET Core 3.1.
We are very excited to get our hands dirty with .NET 5 sometime in Q1 next year. We currently run on .NET Core 3.1. I expect our migration from 3.1=>5.0 will be a total non-event, but we don't want to risk any regressions during our current crunch phase. Our migration from 4.7=>2.0 was the most difficult, but once we got everything off Framework and onto Core things have been going really smoothly with the incremental upgrades. Really hoping this trend continues indefinitely.
The only part of .NET 5.0 that has left me disappointed is the continued lack of polymorphic deserialization support in System.Text.Json - a la Newtonsoft.Json's TypeNameHandling enumeration. This is the only thing holding us back from migrating to this first-party dependency. I have already left feedback regarding our use case in the appropriate dotnet/runtime GH issue.
The biggest new features I am looking forward to are the performance enhancements surrounding startup time, GC, etc. Improved P95 latency is something that will be very welcome in some of our busier environments.
In terms of the overall package that .NET brings to the table, we couldn't be happier. Sure, VS could run a little smoother and some of the configuration/DI stuff can be very aggravating (at first), but overall its a fantastic experience.
FWIW, I just did a find/replace across 66 projects for `netcoreapp3.1` => `net5.0` and it build and passed tests first try. There were a fair few new nullable reference type warnings though!
Would love to see a write up of your challenges / approach. Seems to be a big lack of write ups on this process that I'm sure lots of devs would appreciate!
The core challenge was dealing with 3rd party dependencies (Nugets) relative to each project. We ultimately found that attempting to mix Framework/Core/Standard projects together was an excellent substitute for nightmare fuel. So, the happy path for us turned out to be to do it all at once and only use .NET Core project types throughout (DLL/EXE). Trying to convert your overall solution 1 project at a time hoping for some sort of incremental outcome is probably going to be more frustration than it's worth.
Assuming you bite the bullet on all or nothing, the next challenge will be: Is your code is even supported anymore? This is obviously going to vary wildly depending on your use cases. For us, the Microsoft.Windows.Compatibility shim was enough to restore 100% of the functionality (we rely on System.Drawing and DirectoryServices). But, there was also a lot of other rewrite to support new AspNetCore primitives, and we also moved over to Blazor for web UI (which is more of a rewrite than migration).
Huge endeavor and launch! Looks like mobile app development will be the same with Xamarin
Looking at their issue tracker, it seems watchOS development is a nightmare, there's no support for catalyst, and there's no support for WidgetKit. Widgets are very hot right now, so that was disappointing.
It used to be that if you could make an app for iOS with Swift, you could make it with Xamarin. That guarantee is no longer there.
I don't see any strong reasons to switch to .NET from Java for those who heavily invested in Java already. But I think that .NET is pretty strong, so the same argument could be made for the other direction, for folks who are fluent in MS infrastructure and want to tackle Linux, .NET probably is good enough to keep using it.
.NET could get a huge boost if there was an ability to use Java libraries. There was KVM.NET but that looks pretty dead.
Just decades of over-engineering OOP "best practices" baggage that is impossible to shake off.
Why do people "move" to new languages? Mostly to leave the baggage behind.
https://visualstudiomagazine.com/articles/2020/08/31/aot-sur...
For me, one of the blockers was Winfows.Forms not working with AOT, which appears to have been resolved very recently:
https://docs.microsoft.com/en-us/dotnet/core/deploying/#publ...
So because you can have mutiple versions installed, or you can package it with an app , then the updates can be more rapid.
The problem with .Net framework is that everything, including system services rely on it - that means it needs years of testing and can't have any breaking changes. Basically they decided that packaging .net as part of windows was a mistake.
"Just recompile with the new version!" I hear the cries already, said by people that have never had to support literally a thousand applications in a government data centre, half of which were built years ago by a vendor that is long since bankrupt.
If you have thousand apps, you probably also have a CI/CD system and you can gain fine grained control on your runtime management needs with .net build/publish.
MS does quite a few things poorly but they have done a solid job of operating in large enterprises.
Disclosure: I currently work at Microsoft on the Windows accessibility team. We don't own SAPI or System.Speech, but we consume SAPI in Narrator (via COM in C++).
Microsoft should prioritize fixing this over other tasks with .NET, if they value accessibility users.
It'd be nice for a cross-platform local speech library to be available on .NET, and it'd be nice if the Speech team wasn't likely incentivized to push Azure, but at minimum, existing accessibility functionality should be understood to be crucial.
That pretty much means MS is deprecating it in favor of the Azure speech services...yeah, bummer.
On the other hand, I'm still missing an easier interop with other ecosystems. C# is an easy to use language and I would love to write some common code / business logic / whatever you name it in C# and expose it as webassembly and C/C++, this would cover mobile, web and desktop workloads. You can do something like that with Rust (or at least they claim it, I never tried), but with C# I don't see any _easy way_ doing it. I would be happy if someone could correct me If I'm wrong.
This version will be nearly out of support by then...
.NET 5 reality is: They ported 90% of their app models (e.g. wpf, winforms, ...) and dropped some other (e.g. WCF, WWF, AppDomains, ...). That is not going to change.
.NET ecoysystem reality is: What is not ported until now, will not be ported. .NET Core is now 6 years old (2014?) and everything new is currently .NET Core. Someone who wants to stay in business, has ported already 2-3 years ago.
Tooling in Visual Studio has sucked out loud for most of the Core stuff thus far. There's not a lot of value chasing the churn versus letting it settle out.
1: https://github.com/dotnet/runtime/tree/master/src/libraries/...
2: https://github.com/dotnet/runtime/tree/master/src/coreclr/sr...
It actually does the opposite: it is able to expose memory-alike resources (from e.g. the network interfaces) deep into its consuming programs by using abstractions like Span<T>. And while that sounds like a wrapper, it is actually (depending on the "alike") just a typed and safe pointer.
[1] https://docs.microsoft.com/en-us/aspnet/core/security/authen...
[1] https://www.infoq.com/articles/advanced-architecture-aspnet-...
[2] https://www.claudiobernasconi.ch/2019/01/24/the-ultimate-lis...
[3] https://docs.microsoft.com/en-us/dotnet/core/tutorials/creat...
[4] https://github.com/natemcmaster/DotNetCorePlugins
[5] https://maartenmerken.medium.com/announcing-prise-a-plugin-f...
[6] http://ewer.com.br/plugin-architecture-with-di-containers
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 worrying about some monster CTOR hierarchy. We used to try to keep things "correct" in terms of dependency chain, but we have found that the real world is a lot easier to work with when you permit circular dependencies between services and maintain 1 big flat collection of them. This is basically microservices but without the RPC ceremony and associated nightmares.
So, the implication is that IServiceProvider is a way to "cheat" the system by not requiring you perform an impossible circular CTOR setup where UserService requires AccountService and vice versa. DI cannot resolve dependencies which require each other. In terms of actual harms, I do not really think there are any substantial ones to note. This is technically reflection but only slightly and I haven't been able to notice any performance impact, but we don't do IServiceProvider lookups in tight loops either.
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.
Also, DI is not the same DI containers. If I have three components and inject two into another one, I do DI but for sure will not instantiating a DI container for it ;)
It’s effectively .Net Core 4.0, but they removed the “core” and versioned it 5.0 to make it more obvious that it supersedes and obsoletes .Net Framework 4.8 which lots of organizations are still clinging to.
* Debian can't package F# because it is built using MSBuild, and MSBuild is built using MSBuild. How can it be Microsoft doesn't have the resources to get it into a major distribution?
* Microsoft won't commit to maintaining any cross-platform GUI libraries. You will be relying on some random community project. Compare this with e.g. Python with PySide, which is officially supported by The Qt Company. The Qt Company is 460 times smaller than Microsoft, and they still manage.
Since dotnet core became a thing, I've been building cross-platform apps with great success - mostly Windows and Linux, occasionally MacOS too, and mostly x64, but also ARM too.
Isn't that MAUI?
Speaking cynically, if it's tied enough into the main Microsoft Ecosystem it will have more community buy-in.
You see this happen with other parts of .NET as well, often to the chagrin of the OSS Devs who filled Microsoft's gaps only to be replaced by an (often inferior) solution.
edit:
I guess I can't read. `We expect that Apple will announce new Apple Silicon-based Mac computers any day now. We already have early builds of .NET 6.0 for Apple Silicon and have been working with Apple engineers to help optimize .NET for that platform. We’ve also had some early community engagement on Apple Silicon (Credit @snickler).`
Still wondering for .net 5 though
And they need it to support the development of .NET 6.
I have no idea what it means or the significance of it.
int Factorial(int n) => n is <= 1 ? 1 : n * factorial(n -1);
Then asp.net mvc happened, a whole new paradigm shift. But then I disliked the idea of stuff getting inherited from somewhere. *.cshtml files and all. Soon I realized what the ide is actually doing behind the scenes. For e.g. the cshtml files are compiled and there is an intermediate binary format I guess. (Don't remember well).
This is why I came to like something like express. Guaranteed there is no type safety. (JavaScript is a dynamic language). But I enjoyed the simplicity of it. Ever since I have moved away from the .net platform.
I know this code generation and intermediate binary forms are necessary. But at times I was surprised by it. You find the similar stuff for other stuff you write for e.g winforms, windows presentation apps, etc. I realize there is no other alternative way for such platforms. But I generally disliked the idea that my editor does a lot of stuff behind the scenes. This makes me too dependent on the editor. For e.g. try making winforms app with just notepad. It's not impossible; just very cumbersome.
I have respect for .net. In fact I do write console programs time to time. But I wish stuff was as simple as having a plain editor and getting started.
This is the wrong thing to wish for.
It's like... wishing for "simpler times" of the pre-modern era. You know, the simpler times without dentistry and plagues that make COVID look downright pleasant. Simpler times of backbreaking manual labour, shovelling ditches by hand.
A typical computer can now process 10 billion general-purpose instructions per second. It is a power tool for the mind. Its entire purpose is to eliminate manual labour.
The fundamental concept of computerised information technology is to automate away the processing of information as much as possible.
If you don't get this, then you don't get IT at all.
There is nothing at all good, or somehow more "pure" about programming with Notepad, or VI, or whatever text editor you fancy.
This is like turning off the million dollar backhoe, stepping out of the cabin, and digging the ditch with your hands because you feel that it brings you "closer to the dirt" or something.
when the very _syntax_ of a language is designed such that it's really only usable within a specific IDE, then all of your tooling is limited by the capabilities and decisions of that IDE.
This means nothing anymore. MSFT says that about everything they release and users are still often left with the feeling that they are guinea pigs testing a very unfinished product.
> For Visual Studio users, you need Visual Studio 16.8 or later to use .NET 5.0 on Windows and the latest version of Visual Studio for Mac) on macOS. The C# extension for Visual Studio Code already supports .NET 5.0 and C# 9.
Reading this makes me wonder who is still using Visual Studio. That IDE is so bad it's beyond believe. .NET 5 is a standalone runtime which anyone can install. You can write C# in a text editor and build and run it from the command line. Why the hell do Windows developers need to install an entire new IDE in order to use the latest version of the .NET runtime? It's ridiculous beyond belief.
Really shows that Visual Studio Code is the future. All you have to do is install the latest runtime and update the plugin so it shows you suggestions for all the latest language features. No need to install a new version of Visual Studio Code itself.
> .NET 5.0 is the first release in our .NET unification journey.
This might cause confusion. .NET 5 is basically .NET Core 3.2 but has been renamed to .NET 5 so that .NET Framework 4.x users can finally get convinced to move to .NET Core. They just dropped the Core to make it look more appealing to them, but it's still .NET Core.
Eh? Although I prefer Rider, I don't see how you can make that claim. Yes, it has perf issues, and at least in the past has had some stability issues too, but it's absolutely crammed with features and offers a great dev UX for everything from source control to debugging.
> Why the hell do Windows developers need to install an entire new IDE in order to use the latest version of the .NET runtime? It's ridiculous beyond belief.
To be clear, this is only for existing Visual Studio users. Microsoft has done this for major versions of dotnet core too, and while it's a minor inconvenience, I have believe there is a good reason for it. "ridiculous beyond belief" is a bit strong.
> Really shows that Visual Studio Code is the future.
VS Code and VS are like chalk and cheese - I'm a big fan of VS Code, but for developing with C# I much prefer the features of a full IDE, Rider or VS. Like a debugger, and applying changes during a debug session.
Can't speak to how prod ready this is, would never use a major upgrade like this in production within the first 6 months of it's release. Bless those who have the way but that's madness to me.
Most importantly I could do everything in F# I need to do (or can do in VS), debugging, refactoring, interactive tests, on the free Community Edition of VS. It just happens I use Professional because my company pays for the license.
God help you if you ever wanted to rename a symbol, it was Schrodinger's rename, it would either complete immediately, or never complete, lock up VS, and I'd have to restart. So I had to stop using it, and eventually I stopped using VS altogether.
Rider has its own quirks and annoyances, but it's quick, and lets me type even when it's doing stuff.
There seems to be something very wrong with the architecture of VS.
OTOH I've hardly ever used or installed Resharper (or Rider). When I did try Resharper, I found Visual Studio was dog slow, very much like what you described, and it provided me with very little benefit compared to what I already had in VS.
I do have NVMe M2 Disk if that matters
The other day one of my team (who still uses VS) complained of cut n paste not working (it would paste half the selection).
The basics are broken in my humble opinion
Rider does more of what I want in an IDE for dotnet core. The console is integrated rather than being another window. better vim plugin. better md/json/yaml/helm/k8s file editing.
VS Code is the future of the msft lead dotnet IDEs but rider is so good
But then, I also like Vi and Eclipse so maybe I'm just too forgiving...
There is some truth to this but when it comes to the core .NET stuff that is pretty solid. However .NET core before version 2.0 was mess.
> Reading this makes me wonder who is still using Visual Studio. That IDE is so bad it's beyond believe.
That is your opinion man. Personally I really like VS.
> Why the hell do Windows developers need to install an entire new IDE in order to use the latest version of the .NET runtime? It's ridiculous beyond belief.
They aren't installing a whole IDE. It is an update to the existing VS 2019 version. The newest version of the IDE (which is 16.8) has support .NET 5.0. The vast majority of people that are using .NET core are using the latest Visual Studio 2019 already and this is a minor update (it takes maybe 10-20 minutes to install, so run the updater make a coffee and time you come back you should be good to go).
> Really shows that Visual Studio Code is the future. All you have to do is install the latest runtime and update the plugin so it shows you suggestions for all the latest language features. No need to install a new version of Visual Studio Code itself.
VS code and other alternative .NET IDEs doesn't support many of the things that are typically used around the .NET world e.g. SQL database projects don't work in Rider or VS Code (I just tried it with Rider) and I suspect that a lot of the tooling around that doesn't work. There probably a load of other stuff (that I don't use) that doesn't work either.
It really depends what you are doing.
> This might cause confusion. .NET 5 is basically .NET Core 3.2 but has been renamed to .NET 5 so that .NET Framework 4.x users can finally get convinced to move to .NET Core. They just dropped the Core to make it look more appealing to them, but it's still .NET Core.
I know a lot of people that don't work with Microsoft tech think we are all dumb but we aren't all that dumb. Moving projects from .NET Fullfat to .NET Core maybe a large undertaking (depending on the project) depending on how the project is strutured and what tech it uses.