views:

760

answers:

1

I use 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 the container but I would like to be able to register all controllers from all assemblys to get things more pluggable. I thought that the code below should work but it doesent?

        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)))
                );
        }
A: 

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());
            }
        }
ChrisKolenko