Search code examples
castle-windsorauto-registration

castle windsor auto registration from two different assembly?


    container.Register(
        AllTypes.Pick().FromAssembly(typeof (UserRepository).Assembly)
            .WithService.FirstInterface());

Currently the code above will work fine if the interface are also in the same assembly but it will blow up if IUserRepository is from a different assembly.

Is auto registration from two different assemblies possible? Am I missing something here?


Solution

  • Yes, it's possible to define auto-registration where the interface is defined in a different assembly. We do it, although we use a slightly different syntax:

    container.Register(AllTypes
        .FromAssemblyContaining<ConfigurationService>()
        .Where(t => t.Name.EndsWith("Service", StringComparison.Ordinal))
        .WithService
        .FirstInterface()
        .Configure(reg => reg.LifeStyle.PerWebRequest));
    

    I can't say if the different API usage makes a difference, but I would assume that it doesn't. Rather, I would guess that the cause of the error you experience is that perhaps the assembly containing the interface isn't available.

    Check if Fusion can load the type from that application at all.