Does Autofac provides means to load unload plugin with services/middleware on runtime?

147 Views Asked by At

I am new to autofac and using .net 5-6 in my projects, i built my app in different modules which are loaded in app startup (using alc). But i was wondering if its possible with autofac to load/unload these full app plugins on runtime. much like how wordpress etc. are designed.

you load a zip file with all the plugin dll/files and it manages the info of it on runtime? including services & middlewares initialization.

1

There are 1 best solutions below

3
Travis Illig On

Autofac does not perform the jobs of assembly loading, plugin management, etc. That's up to your application code. If you have your plugins managed as zip files or folders full of assemblies or whatever, it's up to your application to:

  • Perform any file operations - unzip, move, locate.
  • Load the assemblies into memory - Assembly.Load or whatever.
  • Handle any reference problems that the runtime doesn't already handle - missing dependency assemblies, etc.

You can then use the standard Autofac interfaces to make your registrations.

The point is, Autofac isn't a plugin framework it's a DI container. Anything outside of DI is up to you. Even if you're thinking about the assembly scanning logic, Autofac isn't loading or locating the assemblies - it's just scanning assemblies you've already loaded.