0
votes

I have seen many question that ask how to load all referenced assemblies even if not directly used, but I would like to take that a step further. I am building a service and interface that can be extended, the intention is that I could extend the Sender/Receiver with additional types, for example: the interface is responsible for sending SMS messages and can have different adapters, say I have two different applications that want to use SMS, each would have its own implementation of an ISmsAdapter and ISmsReplyAdapter, the assemblies may not necessarily be referenced by the Service (the application comprises of a Windows Service and a WebAPI service to receive replies).

What I would like to be able to do is not just register my autofac modules that are in referenced assemblies, but also register modules in assemblies that are in say a specific folder such as /bin/plugins or something similar

I have not been able to find anything that relates to this other than Caliburn.Micro which has a DirectoryCatalog which does something similar to what I want

Does anyone know how I might be able to achieve this with Autofac please?

1

1 Answers

1
votes

This isn't really an Autofac question so much as a reflection question. Autofac doesn't care how you load assemblies.

Load your assemblies through reflection using something like Assembly.LoadFrom and then use the assembly scanning in Autofac or continue using reflection to manually locate certain types in the assemblies (eg types that inherit from module, types with a certain naming convention, types that implement a certain interface, etc.) and register the types individually in a for-loop.