This presents a couple of challenges:
- A one-size-fits-all solution rarely works, and lazy time-pressured developers will likely leave any unused code in place
- When the time comes to upgrade you must update that code everywhere it’s used, and keeping track of all of places can be a challenge
- Similarly if a bug is found, that needs to be patched everywhere too
In short it’s a maintainability nightmare! What you gain in efficiency at the start of a project can quickly become a burden down the line.
The same can be said for “starter kits”, site-builder solutions, and .NET templates, where they offer a full-fledged site in moments + access to the source code to customise as you need. But customising code breaks future upgradability, effectively forking the project at that point in time.
A Modern Approach
At Bump we found ourselves building the same modules and bits of functionality again and again. We needed an efficient way to reuse things across projects, but also allow us to mix-and-match pre-built features from a central place. We decided to create a system of reusable features and plugins.
Each feature needed the ability to ship its own default views, models, schema – but with flexibility to override and customise at every point.
Features could be versioned and therefore built and upgraded in isolation from client projects. To provide maximum reusability the implementations could be kept lean and aim to support as many Umbraco versions as possible (i.e. v9-v13).
We just needed to work out how…
Enter Razor Class Libraries
Turns out .NET has a pretty neat way of doing exactly this in the form of Razor Class Libraries!
RCLs allow views, static files, and other code to be shipped in a versioned class library & NuGet package.
To setup an RCL we create a new .NET Class Library project and update the csproj file to use the Microsoft.NET.Sdk.Razor SDK: