In a previous post on application parts I created the basic library file to drop into a plugin directory which was then dynamically loaded up through reflection to be consumed in the host application. In this post I will cover what is needed if for example you have services that need injecting via .Net Core Dependency Injection mechanisms.

Add custom attributes to plugin services

As we want these classes and interfaces to be discoverable by our host application, the best way to do this is by decorating them with custom attributes. Custom attributes are simply declared in a class that inherits from System.Attribute

This takes in a name for the plugin service so that it can be differentiated from other plugins.

Then decorate both your service classes and interfaces with this new attribute.

Search the assembly for the custom attribute

So now in the host we can load up the assembly and instead of having to deal with all the other types that are not anything to do with our service, we can just search for our new attribute type.

We want to find all service classes and then find the interfaces that they implement. Our design is very simple and our service class only implement the one interface.

Here we have the class as a Type object and with this we can get the interfaces as a collection; we only need the first item which in our simple case would be IMyService.

As we cannot return a collection from the ConfigureApplicationParts() method, we simply add both the class and interface to a collection defined outside it.

Now use this collection and inject each class and interface into the application as transients.

Happy coding

New to Chrome 77 and also Edge (Chromium) is the native functionality to lazy load images, that is to only request images when the user scrolls the page to a certain position. Although this position is calculated in the browser (I don't know the formula), images are loaded up when it scrolls near to the image position.

It can be achieved by using the loading attribute with a value of lazy in an image element and can also be part of a Picture element as well.

An example with a standard image element:-

An example with a picture element:-

It currently works in Edge (Chromium) Version 81.0.381.0 and Chrome 77 but not Firefox as of version 72.0.1 that I tested with.

By omitting the loading attribute, the browser wil default to auto which means it will determine if the image should be lazy loading. To override this use the eager value which will load the image on page load.

What about a fall back?

For unsupported browsers such as Firefox, Edge Version 44 and of course IE, it is possible to replicate the functionality using a poly fill like this:-

Happy coding

HTTP Endpoint Monitoring for both Windows and Android
WebUp App