The Subtle Perils of Controller Dependency Injection in ASP.NET Core MVC

Some time ago I wrote a blog about how ASP.NET MVC 6 discovers controllers. While a lot has change since then, including the name - now the framework being called ASP.NET Core MVC, the post is still valid and the processes described there haven’t really changed.

That said, there is one extra thing that should be added to it, and that is how external dependency injection containers relate to the process of controller discovery and instantiation, as there is a subtle difference between ASP.NET Core MVC and the “classic” frameworks - MVC 5 or Web API 2. This post is really sparked by the conversation on Twitter with Jeremy and Kristian.

Roslyn scripting on CoreCLR (.NET CLI and DNX) and in memory assemblies

For a while now, the Roslyn C# scripting APIs (Microsoft.CodeAnalysis.CSharp.Scripting) have been portable, and supported cross platform usage.

However, I recently ran into a few difficulties regarding using the Roslyn Scripting APIs in .NET CLI (which is replacing DNX) context. The solution was to use a lower level unmanaged CoreCLR API - and since they it’s not that well documented, I thought it would be beneficial to document it in a blog post.

OmniSharp Canada Tour 2016

I’ve said it a couple of times already, but I sincerely believe that the OmniSharp project is one of the most important projects in the history of .NET. Having an alternative to the “dictatorship” of Visual Studio is fundamentally important to the health of the .NET ecosystem, and OmniSharp has done a tremendous job in that sense (thanks, Jason & David). Fro my side, I’ve been trying to support the project as much as I can - by contributing, speaking or blogging about it, trying to spread the love.

FormatFilter and MediaTypeMappings in ASP.NET Core 1.0 MVC

In the earlier posts, we looked at how formatters work in general in the upcoming MVC Core 1.0 (although at that time it was still being referred to as MVC 6) and how XML formatters can be enabled in your ASP.NET Core application.

This time around, I thought it would be interesting to follow up on that, and discuss another topic that should be very familiar to folks with ASP.NET Web API experience - MediaTypeMappings. They were quite commonly used in Web API, and they have been ported over to MVC Core, and can be enabled via a FormatFilter.

Re-using external view components in ASP.NET 5 & ASP.NET MVC 6

The other day we [explored using view components in ASP.NET 5][1] - as a very nifty replacement for the old MVC ChildActions. View components allow you to package a piece of functionality into a reusable class, along with an accompanying view, that can be invoke from any other view on demand.

Today let’s take this a step further - and let’s see how you can configure ASP.NET MVC 6, to be able to consume view components not just from the current web project but from external sources - external assemblies too. This way you will be able to share and distribute your view components across multiple projects. This is definitely useful for anyone who has - for example - ever worked on a portal-style applications, where building reusable components is one of the most important development activities.

Running ASP.NET 5 website on IIS

As ASP.NET 5 hit RC1 about a month go, more and more folks are looking at production deployments and other real life use cases of it. Going beyond demoware and experiments, to real applications, inevitably leads to thinking about hosting it somewhere - which, if your environment is Windows, most likely means IIS.

I have recently gone through quite some trouble getting it all to work, so I thought it might be useful to document and highlight some of the steps, which hopefully will save a bit of your time.

Adding C# Scripting to Your Development Arsenal

As part of my efforts to popularize C# scripting in the .NET community (which, hopefully, you have noticed by following this blog, my Twitter or my Github) and in celebration of the first stable release of Roslyn scripting packages on Nuget yesterday, I published a guest post at Canadian Developer Connection blog - Adding C# Scripting to Your Development Arsenal. You can read the post here, and hopefully you find it useful.

Running C# scripts and snippets in Visual Studio Code with scriptcs

Recently Microsoft open sourced the Code editor and I think a lot of people would agree that it’s really awesome. The UI based on Electron and the Monaco editor previously used in Visual Studio Online is really snappy and works great.

Visual Studio Code can also now be extended via plugins - and when that was announced, I thought why not make something for scriptcs? There already is a scriptcs plugin for Sublime Text and for Atom, so it only makes sense to have one for Visual Studio Code.

Localized routes with ASP.NET 5 and MVC 6

In my Web API book, in one of the chapters (source here), I’m discussing an in interesting approach towards route localization, using attribute routing.

The whole idea came from the fact that at some point in the past I used to work on a really large application - 70+ language versions, all of which required localizations on the route level.

That approach allowed you to define a single attribute route at action level (as opposed to, well, 70+ routes), and have it auto-translated by the plugged in infrastructure, as long as you provide the mapping to other languages at application startup.

Let’s have a look at how same type of functionality can be built in ASP.NET MVC 6.

Global route prefixes with attribute routing in ASP.NET 5 and MVC 6

In the last post a few days ago we looked at adding a centralized route prefix to attribute routing in ASP.NET Web API.

I got a couple of follow up question about how to achieve the same in ASP.NET 5 and MVC 6 framework. Let’s have a look then (btw: this article is written using beta8 version of ASP.NET 5).

About


Hi! I'm Filip W., a cloud architect from Zürich 🇨🇭. I like Toronto Maple Leafs 🇨🇦, Rancid and quantum computing. Oh, and I love the Lowlands 🏴󠁧󠁢󠁳󠁣󠁴󠁿.

You can find me on Github and on Mastodon.

My Introduction to Quantum Computing with Q# and QDK book
Microsoft MVP