Register all software controllers in the Castle Windsor container from all builds

I am using this code ...

container.Register( AllTypes .FromAssembly(Assembly.Load("MyNamespace.Dashboard")) .BasedOn<IController>() .Configure(component => component.LifeStyle.Transient .Named(ControllerNameFromType(component.Implementation))) ); 

... to register my controllers in a container, but I would like to be able to register all controllers from all assemblies to make things more connectable. I thought the code below should work, but it does not exist?

  Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (var assembly in assemblies) { container.Register( AllTypes .FromAssembly(assembly) .BasedOn<IController>() .Configure(component => component.LifeStyle.Transient .Named(ControllerNameFromType(component.Implementation))) ); } 
+4
source share
1 answer

Check assemblies to see if all assemblies are loaded.

Do something like this if not:

  foreach (string dllPath in Directory.GetFiles(directoryPath, "*.dll")) { try { Assembly a = Assembly.ReflectionOnlyLoadFrom(dllPath); if (Matches(a.FullName) && !loadedAssemblyNames.Contains(a.FullName)) { App.Load(a.FullName); } } catch (BadImageFormatException ex) { Trace.TraceError(ex.ToString()); } } 
0
source

All Articles