Search code examples
castle

castle: register interface proxies by convention


I want to register multiple components implementing the dictionary adapter, but the AllTypes.From.. only picks class-types. I want to do something like this:

        container.Register(AllTypes.FromAssemblyContaining<IFooSettings>()
            .Where(type => type.IsInterface)
            .Configure(component =>
                component.UsingFactoryMethod((kernel, model, creationContext) => new DictionaryAdapterFactory().GetAdapter(creationContext.RequestedType, ConfigurationManager.AppSettings))));

Now I can't seem to be able to create my own version of "AllTypes" since the FromTypesDescriptor ctor is internal. Any ideas how I can accomplish this?


Solution

  • This now works in Castle 3.3.0:

    var dictionaryAdapterFactory = new DictionaryAdapterFactory();
    
    container.Register(
            Types.FromThisAssembly().Where(t => t.Name.EndsWith("Settings") && t.IsInterface)
                .Configure(component => component.UsingFactoryMethod((kernel, model, creationContext) => dictionaryAdapterFactory.GetAdapter(creationContext.RequestedType, ConfigurationManager.AppSettings))));
    

    You have to use "Types" which also picks up interfaces