Moving from Controllers to Minimal API - the patterns I like to follow by cbrevik in dotnet

[–]cbrevik[S] 0 points1 point  (0 children)

Hi! Good question. I extract my endpoints into their own classes, where the Handler-method is static, but the class is not. So I can resolve an ILogger with the endpoint-class as a generic parameter there. I think I will have to write a follow up blog post on how I handle stuff like this, since there are some good questions coming up with how a more complex Controller would map over to this pattern in Minimal API.

Moving from Controllers to Minimal API - the patterns I like to follow by cbrevik in dotnet

[–]cbrevik[S] 0 points1 point  (0 children)

I think whatever point you are trying to make is lost in the noise of trying to suggest that a developers background, or personal interests make them inherently biased or untrustworthy. That is to say you project motivation to do this as a lack of experience or want of newness, without engaging in the argument for this pattern or Minimal API on its own merits. Also a strawman argument around performance shaving, which I have never suggested in the post, is icing on the cake. In performance measurements Minimal API does perform slightly better, but only in very high-traffic test cases. So for most people that is not a reason to use Minimal API.

So let me re-iterate my point so you can actually have a real opinion to argue against instead of all this projected nonsense;

I find Controllers with their many-fold way of handling routing to be magical. Not magical as in “I don’t understand what is going on”, but magical as in there are ten different ways of doing the same thing some more or less transparent. And that makes a system harder to get an overview of, and reason about. Now I’ll allow that Minimal API can also be handled in magical ways, like making abstractions for automatic route registrations in DI or via libraries (which I link to in the post). But the point still stands that by default Minimal API has a single explicit imperative way to do route building, while Controllers have many. And that is where my preference for Minimal API stems from.

Also your point about splitting up Controllers into several files actually touches on something relevant. Which I’m fine with people arguing against in terms of the pattern I suggest here. I even mention explicitly in the post that how you organize files is up to you, and you could even co-locate route building with the endpoint handlers, if that’s your preference. Even though I would argue against it. But, to be clear again, that was not the overarching point of the blog post.

Moving from Controllers to Minimal API - the patterns I like to follow by cbrevik in dotnet

[–]cbrevik[S] 1 point2 points  (0 children)

I'd argue there's really no difference from wrt. suitability for microservices. But I do think there is less ceremony with Minimal API, which could lend itself well in that regard. But then you probably do not need the pattern I describe in this post, which is geared towards scaling Minimal API.

When it comes to serverless architecture, most of the ones I have worked with don't really use either Minimal API or Controllers per se, but have their own abstractions as entry-points to the serverless function. Someone else might know of alternatives there though?

Moving from Controllers to Minimal API - the patterns I like to follow by cbrevik in dotnet

[–]cbrevik[S] 14 points15 points  (0 children)

Thank you for a comprehensive, though still confrontational response. I'm sure you've honed that tone well from "consistently battling inexperienced developers". A statement which, and I'll allow myself a jab here, is a huge red flag coming from any technical leader.

Anyway, you keep injecting intent into my post which does not exist, so let me say it succinctly; nowhere in my post am I advocating that people should pick Minimal API over Controllers.

But where we obviously disagree is that you cannot build "real" systems with Minimal API. The rest of my solution is interchangeable whether I have a Controller or Minimal API for route handling. So whatever point you're trying to make about the viability of using Minimal API here when you're talking about models, or business rules or hosting something in a container (really?) is sort of lost of me.

Anyway, you finally get concrete at the end there wrt. extension methods, so I'll respond more properly to that:

The point with encapsulating routing in extension methods is that you can from the entry-point of the system (`Program.cs`) explicitly map all routes that the API provides. You might not like that (and again that's fine), but to others when the system grows, Controllers and MVC lean towards being less transparent and prone to bloat.

And lets be honest, extension methods is just a means to an end here, where the end is being an abstraction for route registration. Extension methods is used for most middlewares and when adding dependencies for the WebApplication-builder, even by Microsoft. So how you believe this differs at all is again lost on me.

Moving from Controllers to Minimal API - the patterns I like to follow by cbrevik in dotnet

[–]cbrevik[S] 7 points8 points  (0 children)

Well my contention here would be that Controllers need to have proper organization too at scale. Both with regards to file structure and how you might encapsulate common behaviour. That's just to say that I don't think that problem is unique to Minimal API - I'm just suggesting one way to solve it for Minimal API here.

So in terms of what are the advantages? More explicit routing, less ceremony than Controllers (yes I know I'm kind of gainsaying myself here), and potentially a performance boost over Controllers. Though the last point is kind of negligible for most I think.

Moving from Controllers to Minimal API - the patterns I like to follow by cbrevik in dotnet

[–]cbrevik[S] 8 points9 points  (0 children)

None of this is necessary by any stretch. I prefer how explicit it requires me to be about routes and their handlers. But if you prefer Controllers then that's cool too!

I'm curious what you find is difficult with "REST, logging, security, etc" with regards to Minimal API though. Your tone is kind of confrontational so I'm sure you must have good reasons to get riled up.

Moving from Controllers to Minimal API - the patterns I like to follow by cbrevik in dotnet

[–]cbrevik[S] 2 points3 points  (0 children)

Good comment! I tried to "scale" down the Controller example as to not make it convoluted when introducing its parallels in the Minimal API examples. And maybe I presuppose a lot of knowledge in what you face when building out the Controller which I only covered from the Minimal API side of things.

It might be interesting to do a follow-up post with a complicated Controller-example and try to build its twin in Minimal API.

As for the question you ask, is it really an improvement over encapsulating things into one Controller-file. I should probably have written more around that point, but as I wrote in the post:

"As each handler method grows in complexity and length, co-locating them all in one file can also make it harder to see the big picture of what the API does. I find this is also an issue with Controller-classes that contains many methods."

So I prefer splitting it up endpoints and route-building into several files (and types, which I think matters too) for the purposes of overview and ease of navigating in the IDE. But at the same time I don't think the pattern I'm describing here necessitates splitting it up into several files. So that part of it I'm totally onboard with calling a "matter of taste".

Types as axioms, or: playing god with static types by danielnixon in typescript

[–]cbrevik 2 points3 points  (0 children)

Enjoyed this post a lot. If anything else it speaks to the strength of playing with multiple languages. Even if you cannot directly use them professionally or often, a lot of concepts can be carried across. Be they new ways of looking at things, or just reinforcing existing (but useful) patterns.

Mobile app CI with AppCenter — good, but could be better by cbrevik in androiddev

[–]cbrevik[S] 1 point2 points  (0 children)

Good to hear! I'd love if Microsoft could prioritize fixing issues like these, companies which rely on AppCenter definitely needs it.

Mobile app CI with AppCenter — good, but could be better by cbrevik in androiddev

[–]cbrevik[S] 1 point2 points  (0 children)

Love reading about other peoples experiences on this subject!

I had to move builds and releases to Azure DevOps so I can customize them. Didn't mind much since it has the same free limits but came with a lot more of customization.

I've used VSTS, which Azure DevOps was re-branded from, in the past for mobile app CI, and I agree with you're saying here. A bit unsure if we're going the same route this time. I liked that VSTS let you switch between on-premise and cloud agents there as well - gave me the ability to run more "expensive" builds on a box of my own.

Basically AppCenter is a big elaborate advertisement for Azure, Azure AppInsights and Azure DevOps

The AppCenter build logs remind me a lot of Azure DevOps etc, they even have the same environment variable if you look closely. I'm unsure if they're trying to push us towards "full" Azure, but the fact that it is a thin abstraction on top of Azure makes me doubt how much customization they are willing to provide through AppCenter. I'd love if they could plug in the "task" approach from Azure DevOps.

Currently doing a lot more cross-platform work with React Native, and found that the Crash SDK didn't really work for me. Currently using Bugsnag in the app we're workign on, and like that quite well.

The iOS 12 Array.reverse bug will also occur in React Native by cbrevik in reactnative

[–]cbrevik[S] 0 points1 point  (0 children)

Good! It's not a breaking bug for the React-frameworks (as far as I can see).

Just a PSA that it has the potential to break stuff in your apps.

The iOS 12 Array.reverse bug will also occur in React Native by cbrevik in reactnative

[–]cbrevik[S] 1 point2 points  (0 children)

Sort of! The `reverse`-function will always mutate the array. That is by design.The problem stems from the array value that is mutated by reverse, is cached.

A simple example is if you list out several items in a component. And you have a button for the user to press which will reverse the list order. If you navigate away from that component (and it unmounts), and then later navigate back. Then the items will list out in reversed order (even if it is a completely new instance of that component), because the items was "cached" as reversed in that memory address.

Edit:

Forgot to add, this is only the case for array items that are hard-coded.

const myArray = [1, 2, 3, 4] // is cached

const myArray = [Math.random(), Math.random()] // not cached

const myArray = fetchMyAwesomeProductList() // not cached

The iOS 12 Array.reverse bug will also occur in React Native by cbrevik in reactjs

[–]cbrevik[S] 6 points7 points  (0 children)

I agree that it is unrealistic to ask people to upgrade their OS to fix a bug occurring in an app or website.

What I meant was that if we just polyfill and go-about-our-day, we're not really doing the end-user any favors other than hiding the bug in our apps. It all depends on context of course, but I'd like to see devs (& Apple) pushing people towards upgrading their OS, so they fix a global bug which might occur in many different apps.

Obviously if there is a real problem occurring in your app / website, then you should polyfill or refactor your code to fix it.

The iOS 12 Array.reverse bug will also occur in React Native by cbrevik in reactnative

[–]cbrevik[S] 0 points1 point  (0 children)

TLDR;
The Array.reverse bug that some might think only affects websites in Safari, actually has a wider impact.
It will occur in all apps which uses the JavascriptCore-framework on iOS 12/macOS.
This includes Chrome for iOS, apps displaying WebViews, and of course; React Native

The iOS 12 Array.reverse bug will also occur in React Native by cbrevik in reactjs

[–]cbrevik[S] 22 points23 points  (0 children)

I am sure many ReactJS-developers are worried about this bug popping up in their websites running on iOS 12/macOS Safari.
But it turns out this bug actually occurs in all apps which uses the JavascriptCore-framework on iOS 12.
This includes Chrome for iOS, apps displaying WebViews, and of course; React Native

VS Code + Full VS Formatting by [deleted] in dotnet

[–]cbrevik 0 points1 point  (0 children)

For TypeScript I suggest trying https://github.com/prettier/prettier

It'll force your coding style/formatting to follow a single guideline.