diff --git a/content/posts/modular-web-app.md b/content/posts/modular-app-1.md similarity index 67% rename from content/posts/modular-web-app.md rename to content/posts/modular-app-1.md index 4ef6962..7726ba2 100644 --- a/content/posts/modular-web-app.md +++ b/content/posts/modular-app-1.md @@ -1,5 +1,5 @@ +++ -title = "Plugin-Based Web Application in Dotnet" +title = "#1 Plugin-Based Web App in Dotnet - The Idea" date = "2024-01-20T00:00:00+00:00" author = "the1mason" authorTwitter = "the0mason" #do not include @ @@ -13,22 +13,39 @@ hideComments = false draft = false +++ -### Table of Contents + +
-- [Introduction](#introduction) +# Chapters + +Writing those takes time. Expect to see one published per one-two weeks. + +1. Idea, Stack + +2. ~~Loading plugins~~ + +3. ~~PluginBase, IPlugin~~ + +4. ~~Creating plugin, DependencyInjection~~ + +5. ~~Controllers, Views~~ + +6. ~~Hooks and Triggers - better event system~~ + +7. ~~Advanced: Unit tests, unloading plugins~~ # Introduction Have you ever heard of plugins? These are loadable libraries, extending your application. -This article is an overview of my plugin-based web application prototype and mechanisms behind it's features as well as my thought process and decision making during development. This article is, essentially, a step by step guide to making your own plugin-based web app prototype. +This series of articles is an overview of my plugin-based web application prototype and mechanisms behind it's features, as well as my thought process and decision making during development. These articles are a step by step guide to making your own plugin-based web app prototype. -*This article assumes some knowledge of programming and design patterns.* +*I assume some that readers have some knowledge of C# and design patterns* # Problem -Self-hosted web applications can solve different problems and be of use to a variety of different people with slightly different needs. For this to work, I think that such an application should provide an option to extend its functionality. This would allow other people to build an ecosystem of different extensions around it. +Self-hosted web applications can solve different problems and be of use to a variety of different people with slightly different needs. For this to work, I think that such an application should provide an option to extend its functionality. This would allow other people to build an ecosystem of different extensions around it. For example, a shopping website might have plugins for different payment systems, or a comment section under the product page. For me this also means, that instead of making one feature-rich website, that would be so specific to my needs, that it wouldn't of any use to anyone but me, I can write a bunch of smaller modules, that could be used by someone, without having to configure other modules. -# Choose your stack! +# Choosing my stack  @@ -40,9 +57,9 @@ I'm a dotnet developer and I write C# code for living. This project is as much o I haven't seen such plugin-based sites written in C#. There are some projects, using plugin based architecture... Well, there's even a [Microsoft Learn Article](https://learn.microsoft.com/en-us/dotnet/core/tutorials/creating-app-with-plugin-support) about building such an app! -**Q:** Why would I even bother to write all these posts and making prototypes? Even more: Why would someone be interested in such post? +> **Q:** Why would I even bother to write all these posts and making prototypes? Even more: Why would someone be interested in such post? -**A:** You see... there's a problem: Neither `learn.microsoft.com` nor any other webside covers dynamically updating web interface with plugins! If you want to learn about it, it's the right place. Also just loading libraries isn't enough because app also has to provide some ways for plugins to interact with it, which is also covered here! +> **A:** You see... there's a problem: Neither `learn.microsoft.com` nor any other webside covers dynamically updating web interface with plugins! If you want to learn about it, it's the right place. Also just loading libraries isn't enough because app also has to provide some ways for plugins to interact with it, which is also covered here! --- @@ -58,6 +75,17 @@ ASP.NET MVC is a web framework, that incorporates the MVC design pattern and use HTMX uses [Hypermedia as the Engine of Application State (HATEOAS)](https://htmx.org/essays/hateoas/) - it's a principle that leaves all state handling to the server, providing the client only with a set of actions that it can take. Your regular SPA will get raw data from the server (like bank balance) and based on it, it will show or hide certain actions (like we won't show the withdrawal option if balance is 0 or less). With HATEOAS, the server just won't give the link to withdraw money, making this action impossible in the first place. +HTMX would allow this app to be extended more easily as well. Most of the modern JS frameworks require transpiling, bundling and other sorts of stuff. This means that when a plugin is installed the client is most likely will have to be rebuilt. This is slow and needs additional dependencies. + +> Have you heard about Blazor WASM? You can just write client code in C#! + +Blazor WASM does not support dynamic loading for plugins. Because of that, plugins won't be able to extend the client. Also it's initial load time is stupidly slow. + +--- + +The next article will cover the following topocs: Loading plugins in runtime, creating plugin's instances, app-plugin communication. I'll have the link here when I'm done writing it! + + \ No newline at end of file diff --git a/content/posts/modular-web-app-advanced.md b/content/posts/modular-web-app-advanced.md new file mode 100644 index 0000000..de6b364 --- /dev/null +++ b/content/posts/modular-web-app-advanced.md @@ -0,0 +1,71 @@ ++++ +title = "Plugin-Based Web Application in Dotnet" +date = "2024-01-20T00:00:00+00:00" +author = "the1mason" +authorTwitter = "the0mason" #do not include @ +cover = "posts/modular-app/title.svg" +tags = ["dotnet", "web", "prototype"] +keywords = ["prototype", "dotnet", "guide", "plugins", "plugin-based", "web application", "ASP.NET", "C#", ".NET 8", "Programming", "Software Architecture"] +description = "Have you ever thought about making a web application, that could be easily extended by third-party developers? I've been thinking about making this app for a while, so here's my experience..." +showFullContent = false +readingTime = true +hideComments = false +draft = true ++++ + +### Table of Contents + +- [Introduction](#introduction) +- [Why](#why) +- [How](#how) +- [The Prototype](#the-prototype) +- - [IPlugin](#iplugin) +- - [Loading Plugins](#loading-plugins) +- - [Hooks and Triggers](#hooks-and-triggers) +- [Sources](#sources) + + +# Introduction + +This post is about my experience of making a prototype of a web app with plugin support as well as my reasoning. As a result, this app could be extended by adding compiled `.dll` class libraries into a plugins folder. I've made it possible to load not only classes but also views and API controllers. You can check out the final version of this prototype in this [GitHub Repo](//github.com/the1mason/prototype.modularmvc). +Also right now I'm building a web application, using similar concepts. As of now, it's not on github, but you can find it [here](//git.the1mason.com/the1mason/octocore). + + + + +# Why + +Self-hosted web applications can solve different problems and be of use to a variety of different people with slightly different needs. For this to work, I think that such an application should provide an option to extend its functionality. This would allow other people to build an ecosystem of different extensions. + +# Stack + + + +Making a C# web application was my goal from the begginning. That's my backend language for this project, but why MVC and what is HTMX? +Let's have a quick look at worthy alternatives, and then I'll explain my choices. + +`Blazor WASM` does not support runtime assembly loading, which makes client extension impossible. It has [Lazy loading](https://learn.microsoft.com/en-us/aspnet/core/blazor/webassembly-lazy-load-assemblies?view=aspnetcore-8.0), but it still requires these assemblies to be defined in the project file, which is not viable for our case. + +`WebApi +
++ +
+ +
+Dotnet developer
+This is my site. I don’t post here often, so feel free to check out my GitHub.
+You can also check any of my posts below.
Writing those takes time. Expect to see one published per one-two weeks.
+Idea, Stack
+Loading plugins
PluginBase, IPlugin
Creating plugin, DependencyInjection
Controllers, Views
Hooks and Triggers - better event system
Advanced: Unit tests, unloading plugins
Have you ever heard of plugins? These are loadable libraries, extending your application.
+This series of articles is an overview of my plugin-based web application prototype and mechanisms behind it’s features, as well as my thought process and decision making during development. These articles are a step by step guide to making your own plugin-based web app prototype.
I assume some that readers have some knowledge of C# and design patterns
+Self-hosted web applications can solve different problems and be of use to a variety of different people with slightly different needs. For this to work, I think that such an application should provide an option to extend its functionality. This would allow other people to build an ecosystem of different extensions around it. For example, a shopping website might have plugins for different payment systems, or a comment section under the product page. For me this also means, that instead of making one feature-rich website, that would be so specific to my needs, that it wouldn’t of any use to anyone but me, I can write a bunch of smaller modules, that could be used by someone, without having to configure other modules.
+C#
+I’m a dotnet developer and I write C# code for living. This project is as much of an excersise for me as it is an interesting design prototype for C#, that hasn’t been described in detail as much online.
+I haven’t seen such plugin-based sites written in C#. There are some projects, using plugin based architecture… Well, there’s even a Microsoft Learn Article about building such an app!
+++Q: Why would I even bother to write all these posts and making prototypes? Even more: Why would someone be interested in such post?
+
++A: You see… there’s a problem: Neither
+learn.microsoft.comnor any other webside covers dynamically updating web interface with plugins! If you want to learn about it, it’s the right place. Also just loading libraries isn’t enough because app also has to provide some ways for plugins to interact with it, which is also covered here!
MVC with HTMX
+ASP.NET MVC is a web framework, that incorporates the MVC design pattern and uses SSR (Server Side Rendering) to serve content. It is a perfect fit for the HTMX library. This is a compact JavaScript library that extends basic HTML by adding some custom attributes just enough to build your app around it. You can distribute events, make AJAX requests and build truly dynamic app by using as little JS as possible.
+
+HTMX uses Hypermedia as the Engine of Application State (HATEOAS) - it’s a principle that leaves all state handling to the server, providing the client only with a set of actions that it can take. +Your regular SPA will get raw data from the server (like bank balance) and based on it, it will show or hide certain actions (like we won’t show the withdrawal option if balance is 0 or less). With HATEOAS, the server just won’t give the link to withdraw money, making this action impossible in the first place.
+HTMX would allow this app to be extended more easily as well. Most of the modern JS frameworks require transpiling, bundling and other sorts of stuff. This means that when a plugin is installed the client is most likely will have to be rebuilt. This is slow and needs additional dependencies.
+++Have you heard about Blazor WASM? You can just write client code in C#!
+
Blazor WASM does not support dynamic loading for plugins. Because of that, plugins won’t be able to extend the client. Also it’s initial load time is stupidly slow.
+The next article will cover the following topocs: Loading plugins in runtime, creating plugin’s instances, app-plugin communication. I’ll have the link here when I’m done writing it!
+ +