Dependency injection doesn’t strictly require frameworks – Code smells series

This post is part of a 10-week series by Dino Esposito (@despos) around a common theme: code smells and code structure.

Last week, we looked at using constructors vs. factory methods, and how sometimes factories can help make our code more readable. In this post, let’s look at the concept of dependency injection to help make services available in our code, as well as make it more extensible.

In this series: (we will update the table of contents as we progress)

Continue reading

Posted in How-To's | Tagged , , , , | 13 Comments

Performance improvements in ReSharper 2018.2 EAP: EditorConfig support

In a previous series of blog posts about ReSharper’s performance, we promised to continue sharing our activities in that area. This post will talk about a significant refactoring of EditorConfig support and other fixes we’ve implemented based on the performance snapshots you’ve sent us (thanks!).

In this series (we will update the table of contents as we progress):

Let’s have a look at these in more detail.

Performance improvements around EditorConfig support

Back in ReSharper 2017.3, we added EditorConfig support to adjust ReSharper inspections settings via .editorconfig and StyleCop configuration files using both ReSharper-specific and Roslyn-specific records. However, it was slow and added a noticeable performance impact on Visual Studio – which is why there was a setting called Read settings from editorconfig and project settings, disabled by default.

ReadSettingsFromEditorConfig

Continue reading

Posted in How-To's | Tagged , , | 6 Comments

Publishing ASP.NET Core web applications to IIS, FTP, and more with Rider 2018.2

The latest Rider 2018.2 EAP (Early Access Preview) build comes with a long-awaited feature: publish support for ASP.NET Core web applications. Two new run configuration types were introduced that can deploy our app using MSDeploy (local and remote IIS), Kudu, FTP and FTPS/SFTP.

Publish support through run configurations

Rider introduces two new run configurations: Publish to IIS and Publish to custom server. Both serve the purpose of deploying our ASP.NET Core web application to a local or remote server, however, they use different means to do this:

  • Publish to IIS uses MSBuild and MSDeploy to package and publish our application.
  • Publish to custom server uses MSBuild and Rider’s built-in tooling to upload our application artifacts using FTP and FTPS/SFTP.

From the Run | Edit configurations… menu (or by editing configurations from the toolbar), we can add any of these two run configurations:

Create new run configuration for publishing a web application using Rider

Once added, we can perform our deployment from Rider’s toolbar (or by hitting F5 when the deployment run configuration is selected).

Deploy to Azure App Service from Rider using Publish to IIS

Now let’s look at both new run configuration types and how we can configure them. Continue reading

Posted in How-To's | Tagged , , , , , | 2 Comments

Ref local re-assignment – C# 7.3 in Rider and ReSharper

The Early Access Preview (EAP) versions of ReSharper 2018.2 and Rider 2018.2 come with support for C# 7.3. In this series, we are looking at these new language features in C# 7.3. Today, we let’s check out ref local re-assignment.

This post is part of a series (we will update the table of contents as we progress):

Ref local re-assignment

In C#, it’s been possible for a while to work with references, using the ref keyword. For example, it’s possible to return a reference to a Person that is already in memory, rather than return a by-value version that will be copied.

Continue reading

Posted in How-To's | Tagged , , , , , | 3 Comments

Every method begins with “new” – Code smells series

This post is part of a 10-week series by Dino Esposito (@despos) around a common theme: code smells and code structure.

Last week, we looked at additional ways of bringing the code language closer to the business language. Today, we will discuss the usage of new vs. factory methods, and if we can make our business logic even more understandable.

In this series: (we will update the table of contents as we progress)

Constructors and factories

In object-oriented languages, common ways to get a new instance of a type are using a constructor or using a factory method.

A constructor is a method in the class that enjoys special treatment from the compiler, and is defined with a specific syntax compared to other methods. In both Java and C#, the constructor is a method that has the same name as the class and can’t be called explicitly on an existing instance, unless via reflection or via System.Runtime.

Continue reading

Posted in How-To's | Tagged , , , , | 13 Comments

Unit test coverage and continuous testing. Now in Rider!

Rider+dotCover

With each Rider release, we do our best to bridge the gap between Rider and the ReSharper Ultimate bundle. The top in-demand feature has certainly been “Rider + dotCover” integration. So, without further ado, please welcome the latest Rider 2018.2 EAP build – the first Rider version ever that features unit test code coverage and support for continuous testing!

What exactly is dotCover able to do in Rider, and how is it going to be licensed? Read the answers below.
Continue reading

Posted in How-To's | Tagged , , , , | 17 Comments

Unmanaged, delegate and enum type constraints – C# 7.3 in Rider and ReSharper

Last time in our series about C# 7.3 language features, we covered tuple equality. Today we will look at unmanaged, delegate and enum type constraints. The latest Early Access Preview (EAP) versions of ReSharper 2018.2 and Rider 2018.2 come with language support for C# 7.3, do give them a try!

This post is part of a series (we will update the table of contents as we progress):

Ever since C# 2.0, when generics were introduced, it has been possible to set type constraints on generic parameters. For example, we could specify that the type constraint should implement a specific interface, and perhaps also have a parameterless constructor:

Generic type constraints can be added on class declarations, method declarations, and local functions. They allow us to constrain the types which can be used with the class or method we are creating.

Up until now, these constraints included reference type constraint (class), value type constraint (struct), interfaces or base class constraints, and whether a parameterless constructor should be present (new()). With C# 7.3, three new generic type constraints are introduced (proposal): unmanagedSystem.Delegate and System.Enum.

(Fun fact: the CLR already supported these constraints, however the C# language prohibited using them. Jon Skeet has a blog post on making these constraints work in earlier C# versions.) Continue reading

Posted in How-To's | Tagged , , , , , | 2 Comments

Debugging ASP.NET Core apps in a local Docker container

Good news, everyone! Our latest Rider 2018.2 EAP (Early Access Preview) build comes with support for debugging ASP.NET Core apps in a local (Linux) Docker container. Being able to attach the debugger to a Docker container helps to validate our application locally in a Linux Docker container that should closely resemble production. Let’s see how this works!

Setting up Rider and Docker

Rider comes with Docker integration. We’ll have to configure Rider to connect to our local Docker daemon to enable it. Under Build, Execution, Deployment | Docker in the settings, we can add a new connection to Docker. Typically all we will need to configure is the engine API URL, which usually is tcp://localhost:2375.

Add Docker in Rider settings

Note that by default, Docker for Windows does not expose the daemon to Rider. This will have to be enabled in Docker’s settings:

Expose Docker daemon to Rider

Once configured, we can open the Docker tool window (View | Tool Windows | Docker) and inspect running containers, images, container logs and so on:

Docker tool window in Rider for managing containers and images

With that out of the way, let’s create a Docker run/debug configuration for our application. Continue reading

Posted in How-To's | Tagged , , , , | 11 Comments

Initial Blazor support in ReSharper and Rider 2018.2 EAP

In February, the ASP.NET team announced the experimental project “Blazor” – a single-page web app framework built on .NET that runs in the browser with WebAssembly. Blazor is great news for all web developers and those who want to try something new. Basically, it allows us to create dynamic websites without writing any piece of JavaScript. Client-side logic can simply be implemented using C#, which is then compiled to use open web standards (WebAssembly).

A brief look at Blazor

Even though Blazor is declared experimental for now, we’ve added initial support for this promising framework in both ReSharper 2018.2 EAP and Rider 2018.2 EAP. For instance, code completion includes all the possible directives, like page (routing), inject (service injection) and function (component members):
Code-completion for Blazor directives

Blazor allows to compose components from other components with simple HTML tags, which turns out to be a very flexible approach. For instance, when decorating a member with ParameterAttribute, we can set this member from any other component with a HTML attribute.

The ParameterAttribute is not yet supported, but for completeness, let’s see how this works:
Component members in function-block

Continue reading

Posted in How-To's | Tagged , , , , , , | 7 Comments

Put it down in layman’s terms – code smells series

This post is part of a 10-week series by Dino Esposito (@despos) around a common theme: code smells and code structure.

So far in this series about code smells, we’ve made the point that keeping the language of the code close to the language of the business is crucial to reducing misunderstandings and speeding up development. Naming classes, methods, and sparse values appropriately is part of the job. Today, let’s look at bringing the code even closer to the business language!

In this series: (we will update the table of contents as we progress)

A very common scenario in nearly all types of code is checking the value of a variable against a fixed range of values, mostly constants. In modern programming languages, the enum type is the artifact used to declare a list of named integer constants.

While the value of any constant is an integer, an expression that evaluates to any of the constants is of a type that inherits from System.Enum. In the code snippet, it is RoomState. Enum values are typically assigned to variables or evaluated in conditional statements.

Even when all you need to do is check a value against a constant, you never know what can happen next as the code base grows. Turning explicit constants into enum values is a good first step. Continue reading

Posted in How-To's | Tagged , , , , | 4 Comments