Posts

ASP.NET MVC vs ASP.NET Core: Practical Differences

Image
ASP.NET Core has been around for a while, but not everyone is using the new framework yet. If you're someone who's migrating from ASP.NET MVC to ASP.NET Core, you might be wondering what the differences between the two frameworks are. In this post, I will share the main differences between the two, from the point of view of a developer who has worked with both. Here is an overview: Dependency injection is built-in. Controllers are unified. Client-side assets are centralized. And more - read below! Dependency injection is built-in Dependency injection is a popular pattern in object-oriented languages that helps make code maintainable. With ASP.NET MVC, developers had to make use of 3rd-party NuGet packages to enable dependency injection in their projects. In ASP.NET Core, dependency injection is baked into the framework. There is no need to use any NuGet package, although using 3rd party DI packages is still supported. Dependency injection is supported n...

Solved: Unable to publish to Azure App Service from Visual Studio

Image
I recently created an Azure App Service and tried to publish a new ASP.NET Core web app using its publish profile downloaded. When i did that, I encountered an error: Web deployment task failed. (Could not connect to the remote computer ("[redacted].scm.azurewebsites.net"). On the remote computer, make sure that Web Deploy is installed and that the required process ("Web Management Service") is started. Lear more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_DESTINATION_NOT_REACHABLE.) The requested resource does not exist, or the request URL is incorrect. Error details: Could not connect to the remote computer ("[redacted].scm.azurewebsites.net"). On the remote computer, make sure that Web Deploy is installed and that the required process ("Web Management Service") is started. Lear more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_DESTINATION_NOT_REACHABLE. The remote server returned an error: (404) Not Found. Here...

Immutability

Last time, we looked at pure vs impure functions and we said that functional programming favors pure over impure functions. Using pure functions leads to another concept: immutability . Immutability means that a variable can only have its value set once. After that, the value never changes. So much so that in functional programming, the phrase "assigning to a variable" is often replaced by "binding to a symbol", since the word "variable" is not applicable anymore. Let's consider a non-immutable example: // Declare a class named Car public class Car { public string Color { get; set; } public bool IsStarted { get; set; } } // Instantiate a new instance var myCar = new Car { Color = "Red", IsStarted = true }; // After that, change the values of the car's properties myCar.Color = "Blue"; myCar.IsStarted = false; The properties inside of the Car class are not immutable since they can be changed after...

Pure vs Impure Functions

Image
My partner, who is also a developer, once asked me what the difference between functional and object-oriented programming is. There are many differences, and this post explores one of them: the usage of pure and impure functions. What are pure and impure functions? A pure function does not have side effects. A side effect is a change in state that happens outside of a function that gets persisted even after the function goes out of scope. Impure functions are everything else. Here are some examples to clarify. First, a pure function: // Pure int GetSum(int a, int b) { return a + b; } That is a pure function, because it does not affect any state that is outside the scope of the function. Consider this impure equivalent: // Impure int sum = 0; void ComputeSum(int a, int b) { sum = a + b; } That is an impure function, because it modifies the sum variable, and the modification persists even after the method has gone out of scope. When using an object-or...

My Vue.js Experience

Image
Last year I wrote about Getting Started with Vue.js . I've been using Vue.js extensively from around that time up until now. In this post I will share my experiences with using the framework. It's Still Very, Very Easy With other JS frameworks I've tried, building simple apps and tutorial-type apps were easy. But, as the application's complexity grew, the development effort grew as well. For example, when working with AngularJS, it sometimes wasn't easy to use 3rd party plugins. Because AngularJS was a framework, any 3rd party plugins had to have an AngularJS port for them to work properly. If such a port doesn't exist, extra work is involved in order for them to work with AngularJS (eg. calling $scope.$apply() in appropriate places). That problem simply doesn't exist in Vue.js (at the very least, I haven't experienced that yet). I can use popular JS packages such as axios , lodash , even jQuery and integrate them into my app with absolutely ...

The Tyranny of Horizontal Architectures (and How You Might Escape): Part 2

Image
In part 1 of this series , I talked about the pains that I and my colleagues have experienced when working in code bases that used N-tier data-centric architectures. In this post, I will detail one approach which has allowed me to escape that madness. Lasagna Code We've all heard the term "spaghetti code". But there's also "lasagna code": "The object-oriented version of spaghetti code is, of course, 'lasagna code'. Too many layers." - Roberto Waltman — Programming Wisdom (@CodeWisdom) February 24, 2018 I use that statement to remind myself that layers can sometimes do more harm than good. That also reflects my experience. Of course, it's not really the number of layers that's the problem, but rather, how the dependencies between those layers are set up and what abstractions those layers represent. Consider this familiar diagram of a data-centric N-tier architecture: Or even a diagram of a DDD-inspired but sti...

The Tyranny of Horizontal Architectures (and How You Might Escape): Part 1

Image
You've seen it before. You have been tasked to make a seemingly simple change on a web page. Add a couple of fields, perhaps. Or add new functionality, but still CRUD-like in nature. "Piece of cake," you say. You then proceed to make a change to the HTML. Then to the viewmodel. Then to the business logic layer, which I will also call service layer. Then to the repository layer. Then to the database. (You could also do it in reverse.) All those steps just to add a couple of fields. Which is kind of okay, maybe no big deal. But, as the infomercial says, "Wait, there's more!" Exhibit A: Implementing Functionality Involving Multiple Entities Before we immerse ourselves in the madness, let's set up the domain: an online retail site. In your database, there are Product and Order tables, which have a many-to-many relationship between them. You are following a data-centric N-tier architecture, and therefore there is a repository layer with classes su...