0

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.

Alok
  • 808
  • 13
  • 40

1 Answers1

0

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.

Travis Illig
  • 23,195
  • 2
  • 62
  • 85
  • k got it, but now to my second half of question does with autofac DI can i register services/middlewares on runtime? – Alok Feb 23 '22 at 17:59
  • If "at runtime" means "when you're building your container using `ContainerBuilder`," sure. You can also make registrations in child lifetime scopes as you create them. You should [check out the docs for examples](https://autofac.readthedocs.io/en/latest/lifetime/working-with-scopes.html) and **just try a few things out to see**. The question you're asking about "registration at runtime" - is _exceptionally broad_ so there's not a simple "yes or no" answer. Autofac is VERY flexible, and your app sounds like it has some complexity. You won't get something concrete here. – Travis Illig Feb 23 '22 at 19:27
  • thanks for the input , i will definitely be reading them. from runtime i meant , after the main app initialization is done to any future date.. like i installed my app on server today and a week later i want to load plugin with service/middleware without restarting whole app using autofac DI container. with default DI of net core this is not possible. – Alok Feb 24 '22 at 13:33