Castle Windsor can't find installers in assemblies
Asked Answered
M

2

11

I have code in my global.axax:

protected void Application_Start()
{
    WindsorContainer = new WindsorContainer();
    WindsorContainer.Install(FromAssembly.InDirectory(new AssemblyFilter(AppDomain.CurrentDomain.RelativeSearchPath)));
    ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(WindsorContainer.Kernel));
//...
}

When I debug global.asax, code FromAssembly.InDirectory(newAssemblyFilter(AppDomain.CurrentDomain.RelativeSearchPath)) finds all my project dll's (there are 7 dll's). 3 of them contains implementation of IWindsorInstaller interface, for example:

class WindsorInstaller : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        var services = AllTypes.FromThisAssembly().Where(type => type.Name.EndsWith("Service"));
        container.Register(services
            .WithService.DefaultInterfaces()
            .Configure(c => c.LifestyleTransient()));
        container.Register(Component.For<ISession>().ImplementedBy<AspnetSession>().
            LifeStyle.Transient);
        container.Register(Component.For<ICache>().ImplementedBy<AspnetCache>().
            LifeStyle.Transient);
    }
}

But when I sets breakpoints, it is only 1 installer called, 2 other was skipped. It's funny, but I have another working project from what i copied code.

Marrissa answered 4/2, 2012 at 14:57 Comment(0)
S
15

Your installer class should be public. Your current installer class has no access modifier, hence defaults to internal - and is invisible to Windsor. The Castle docs specify this here: https://github.com/castleproject/Windsor/blob/master/docs/installers.md.

Springtail answered 4/2, 2012 at 20:21 Comment(2)
Happens to all of us, all the time :)Springtail
hmmm, the docs have moved apparently, I will update the link.Springtail
P
0

Check all the assembly names from Project->Right Click->Properties. when using type.Name.EndsWith("Service") your assembly name, and default namespace might be missing the word(Including the project you are executing from. E.g. WebAPI project or UnitTest project). That's why you are not able to get the desired assembly.

Pontianak answered 1/9, 2021 at 5:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.