0

I'm using Autofac to register the controllers of my asp.net mvc 3 web application. At the moment I have to load the DLLs that contains the controllers (plugins) and after that I will register the types. Now, the problem cames from the fact that I have a PluginLoader class that will handle all the stuffs from the assembly loading to the types registration. This class is also registered in the autofac container. The problem is, how can I use that class if before resolve it I must build the container? I mean, I build the autofac container, I resolve the PluginLoader class, I call the method that scan the assembly and find the controllers but then the container is alredy built...

EDIT 1

PluginManager is the base class that manage all the plugins. It depends from the PluginLoader class that basically loads the assemblies with the Assembly.Load method and scan the DLLs to search for MVC controllers. These class are registered as singleton in the autofac container. Now, the PluginLoader should register with autofac the controllers too. But before calling the method that does this I must resolve the PluginManager class from the container and this is the problem. It seems a "circular dependency" or something similar. At the time that I resolve PluginManager the container is alredy built

6
  • But you shuld be able to add bindings even if the container has already initialized Commented Jan 10, 2012 at 20:22
  • sure but I read that this is not the best practice. It's discouraged to do it, only in rare cases you should update the container after that it has been build (this is what is written in the autofac docs) Commented Jan 10, 2012 at 20:24
  • And that what i wanted to ask you, why you build your dependencies while you have a DI framework in place? Commented Jan 10, 2012 at 20:26
  • I don't understand your question. Can you be more explicit? Commented Jan 10, 2012 at 20:30
  • What kind of dependencies does PluginLoader require? I wonder if you could re-implement PluginLoader as an IRegistrationSource? Commented Jan 10, 2012 at 22:26

1 Answer 1

0

PluginLoader sounds like it is part of your bootstrapper - try making PluginLoader derive from Module (an Autofac class) and then register the module with the container. The module can encapsulate plugin-loading logic in its Load() method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.