Umbraco v9 findings

So much for “taking a summer break from blogging”. 😂

This week I had a little room left in my schedule for studying new tech and obviously I took that time to get up to speed on Umbraco’s new major version built on dotnet core.

Umbraco v9 is still in beta mode (RC coming next week) but I keep getting asked almost every day at work "When will it be ready?", "What is new?" and "When will it be stable?".

So I thought I would take it for a spin.

Getting started
One problem is that there is little or none documentation available so far. This is not strange seeing how it’s still in beta but it made playing with it a bit harder. I also tried raising a question on Twitter to see if anyone had some code they could share, but except for a few snippets, the response I got was mostly: "Oh I also want that!".

So I thought I would create a project that would help anyone in my position in the future on quickly getting started with Umbraco v9 by creating a demo site and share it on GitHub.

And here is the result: Adolfi/UmbracoNineDemoSite

You can read more about the solution, content and how to use it in the project readme, but I thought this blogpost would cover a few findings so far that was new to me in Umbraco v9 and that could be a nice "heads up" to other Umbracians:

New project structure
So one of the few things you’ll notice straight away is the new project structure. Startup.cs, Program.cs, wwwroot, appsettings.json etc. are all things you might be used to if you’ve worked with dotnet core before, but if not this might seem scary at first. But it’s really not. After a little while you notice the structure makes a lot of sense and the project feels really nice and trimmed! The most scary thing I guess is there is no web.config anymore! 😱

Goodbye RenderMvcController. Hello RenderController!
So the good old RenderMvcController is now called RenderController and it has a few nice changes. For instance using the explicit constructor you are no longer forced to pass in an UmbracoHelper, which will make mocking and testing a lot easier. All default dependencies injected are now interfaces, NICE!! 😍

Registering your own services
A lot of hardcore core devs seem to like having to register their dependencies in the Startup.cs file and you can do this in Umbraco v9 using something like app.UseUmbraco().UseWhatever().. Somethimes it feels like anytime you google something for dotnet core the answer always involve you having to fiddle with the Startup.cs file.

Me however I have never really liked the Startup.cs in the few dotnet core projects I have been introduced to, because I think it has a tendency to become bloated and honestly quite ugly.

I liked the concept introduced in v8 of IUserComposer's where all my services was responsible for register itself and declare what other dependencies had to be registered before it.

Luckily, in v9 you can use both these approaches. So for my already mentioned demo site, I only used IUserComposer's. (I didn’t even touch the damn Startup.cs file).

await Component.InvokeAsync vs. Html.PartialAsync
This is probably one of the things I am mostly excited about. I can’t really say why, but I really like this new way of managing and rendering components in dotnet core using something called ViewComponents.

So instead of having SurfaceControllers responsible for rendering your blocks, you should now use ViewComponents for handling these tasks.

Here is an example from the demo site on how to create a view component and here is how you render it.

Splitting up a big view in to smaller chunks is still very much possible using partial views, except now you can use Html.PartialAsync(). But for components that handles logic and separate view models, ViewComponents is what you are looking for.

Since this demo site is still very much a work in progress I will probably do one or more follow up blogposts like this one as I discover more new things in v9. Stay tuned.

Cheers friends! ❤️