How do i use WindsorInstaller across multiple asse

2019-07-16 06:47发布

问题:

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

回答1:

You could use AllTypes.FromAssemblyInDirectory...

container.Register(AllTypes.FromAssemblyInDirectory(new AssemblyFilter(folderPath)));