As the festive season has come and gone and things are picking up again, I thought I would post a personal item about how I got into developing on the .Net stack. Feel free to add YOUR story to the comments section below.

It all started around the summer of 2001 while I was working for the NHS here in the UK. I had only been working there since the January and was brought in to create and maintain the Intranet that the Hospital Trust was using for all internal communication outside email. I was developing using classic asp back then on the Microsoft Visual InterDev platform. Then one day my manager came in and dropped a folder of CD ROM's onto my desk and asked me if I could have a look at it and see if it is of any use. I think she was handed it to her whilst at a developer conference the previous week in London. Anyway it turns out to be Visual Studio .Net beta and I happily installed all 5 disks of it. Now what?

I tried getting into creating a web application as well as a desktop application using Visual Basic .Net, but I admitted defeat and went back to my usual day to day work of developing classic asp.

Then a few days later I had another attempt and did get a bit further, but I wanted database connectivity and a simple grid to display it without having to mess around with paging and master detail pages. So again I gave up.

A few days later I was handed an issue of the newly published .Net Magazine (I think it was called) and on the front cover was an introduction to .Net and the new C# language. I delved right in and along with the 4 guys from Rolla website I managed to get a simple web application up and running, connecting to a database and display the data the way I wanted.

Soon I was getting more experienced, to the point that I proposed the whole Intranet be rewritten in .Net 1.0 when it came out officially. My manager was happy with this as she saw it as future proofing the project. It didn't take too long to redevelop the whole thing as there wasn't much in the way of dynamic pages at that point. Running on .Net with a SQL Server back end gave us scope to add much more functionality than there was on the original site. Some of the functionality included a calendar of events for the hospital, a chat client, classified adverts posting and even a CMS so I could hand over the publishing to an editor. As soon as .Net 1.1 came out, the site was again migrated as 1.1 was not compatible with 1.0. Whilst working at that NHS trust, I also developed information portals for local GP practices to share data with the hospitals in the trust and even created XML data feeds (before WCF) to help with this. All this was developed using Visual Basic .Net as my main experience before this was Visual Basic v5 and v6. However this was the last place I used it as after this I trained myself up to use C# using Bob Tabors excellent Learn Visual Studio.Net.

Fast forward 11 years and several job moves I ended up contracting where my first client was the same NHS Trust I started in. To my surprise the Intranet was still running on the technology stack that I created it with all those years before. They had plans on moving over to SharePoint in the near future, but it was good to see an old project still running.

So that is my story, how did you get into .Net development?

Happy New Year and happy coding.

Recently I have been working on a large ASP.Net Core web application that also needs to have pluggable components so the main application can be deployed with or without them. It is possible to add a reference to another project in the Visual Studio Solution and have what are called Areas, but I don’t want this dependency so I went for Application Parts.

An application part is a .net assembly that can be used in the main application through reflection, you just need to tell the Startup class to look for them and include them with any other services.

This can be done through the ConfigureServices method in startup.cs

The ConfigureApplicationParts method is where we search for a Plugins directory and iterate through any libraries we find.

This Plugins directory must be in the bin directory of the main application like this:-

image

For this example I am using a separate ASP.Net Core 3.0 MVC application called Plugin which comprises of Controllers, ViewModels, Views, CSS and JavaScript files. I want them all packaged up and dropped into the Plugins directory of the main application.

When this is done, the Plugin project creates a plugin.dll and a plugin.View.dll which is then loaded within the ConfigureApplicationParts method and depending on its name will be added to the ApplicationParts collection. As can be seen in this code above, it is expecting compiled Razor views. Lets go over this and see how we can embed these resources.

In the Plugin project, right click the project in Solution Explorer and choose Edit Project File

image

Make sure there is an element for ItemGroup and add the views as an embedded resource.

The **\* tells it to include all subdirectories.

So what about JavaScript and styles? Right click on each file in Solution Explorer and choose Properties. Under Build Action, select Embedded resource.

image

This can also be done when editing the project file by removing and adding the resources like this:-

But occasionally I have had issues with this method and the project has refused to load after saving.

Out of the box, a ASP.Net Core 3.0 MVC application doesn’t have a styles section in the Layout file, so add one after the other CSS file references in the main application like this:-

Going back to the Plugin project, we need to add these styles and scripts to the view. To do this we need to load itself as an assembly and find any embedded resources, of which we know there should be one each for the CSS and JavaScript from earlier. I have put it in the Index view of a Plugin controller, but it would be better refactored out and injected in. For simplicity sake:-

Where the PageViewModel is:-

Again, feel free to refactor, but this will get you up and running.

The name of the resource by default will be the namespace of the application appended with the directory structure of the resource, but if you are unsure of what to insert into GetManifestResourceStream(), you can set the Plugin project as the startup project, debug and look at:-

So now the PageViewModel contains both resources as strings, so in the View add the model and the sections for scripts and styles.

Again for simplicity sake I have this as the plugin.css style:-

This as the plugin.js script:-

Build the Plugin project and drop the Plugin.dll and Plugin.Views.dll into the main application plugin directory mentioned earlier. If you already have the main application running in IIS Express, you will need to stop it by right clicking the icon and choosing Exit.

Finally set the main application as the startup project and run it. As I have my plugin controller route set to /Plugin/Index, you can navigate to this path and the plugin will display its very simple message. Also with the browser developer tools open you can see the console.log message as well.

image

You can find this solution on GitHub here:- https://github.com/asteropesystems/Application-Parts-Sample-Solution

Happy coding.

HTTP Endpoint Monitoring for both Windows and Android
WebUp App