2

I am using Castle Windsor to handle my Dependency Injection and it has been working great up until now.

However, i am now trying to extend my project and add some additional libraries - im now struggling to figure the best way to leverage Castle.

I currently have the following assemblies

MyProject.Interfaces (contains IDBContext interface) MyProject.BusinessLogic (contains the Castle Windsor implementation) MyProject.DataAccess (contains implementation of IDBContext)

I currently have an installer called DBContextInstaller and it simply implements the following:

public void Install(IWindsorContainer container, IConfigurationStore store)
{
    container.Register(AllTypes.FromThisAssembly()
                .BasedOn<IDBContext>()
                .WithService
                .DefaultInterface()
                .Configure(reg => reg.LifeStyle.PerWebRequest));
}

I now have a new Assembly in this project - lets call it MyProject.UserService and it happens to have a new concrete implementation of IDBContext.

So my question - how can i change my Container.Register statement to have it inspect multiple libraries. NOTE i totally expect to have more and more libraries added to this scenario in the future. I would love for this installer to just find all implementations.

TIA

Adam Stewart
  • 1,983
  • 1
  • 18
  • 25
  • If you have multiple implementations of `IDBContext`, which one should the application pick? Or is `MyProject.UserServices` used in another application (thus are you sharing assemblies over multiple applications)? – Steven May 05 '11 at 16:01

1 Answers1

4

You could use AllTypes.FromAssemblyInDirectory...

container.Register(AllTypes.FromAssemblyInDirectory(new AssemblyFilter(folderPath)));
Mark Seemann
  • 225,310
  • 48
  • 427
  • 736