views:

180

answers:

3

Hi Every one in code i can do some thing like this:

container.Register(AllTypes.FromAssemblyNamed("AssemblyName"));

can i do the same thing using Configuration file "Windsor.Config"???

+1  A: 

I am pretty sure that only with the fluent configuration API can you set up conventions for your application so that as you create new components you aren’t required to register them individually, as you example shows.

heads5150
A: 

You can write a trivial facility to do that, e.g.:

AllTypesConfig.xml

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <facilities>
    <facility id="alltypes">
      <assemblies>
        <item>Castle.Core</item>
      </assemblies>
    </facility>
  </facilities>
</configuration>

code:

public class AllTypesFacility : AbstractFacility {
    protected override void Init() {
        var asmList = FacilityConfig.Children["assemblies"].Children;
        foreach (var asm in asmList)
            Kernel.Register(AllTypes.FromAssemblyNamed(asm.Value).Pick());
    }
}


var container = new WindsorContainer(@"..\..\AllTypesConfig.xml");
container.AddFacility("alltypes", new AllTypesFacility());
container.Resolve<NullLogger>();

If you need more flexibility it will get progressively harder to represent the fluent config in XML.

Mauricio Scheffer
+2  A: 

Responding to your comment.

There's also a 3rd way (in Windsor 2.5, currently in beta 2 - final release is expected very soon).

You can have each of your modules reference Windsor, and each module have its own set of Installers.

Than you can use the new directory scanning capability to install components from all these assemblies:

// In your root assembly
var container = new WindsorContainer();
container.Install(   
   FromAssembly.This(),
   FromAssembly.InDirectory(new AssemblyFilter("Modules")),
   Configuration.FromAppConfig()
)

In addition if you have components following identical structure you can also register components from multiple assemblies in single installer. See more here.

container.Register(
   AllTypes.FromAssemblyInDirectory(new AssemblyFilter("Modules"))
      .Where(t=>t.Namespace.EndsWith(".Services"))
      .WithService.DefaultInterface()
);
Krzysztof Koźmic
Very cool! I didn't know about this overload for Install(). I usually resolve all the installers first and then call Install() individually.
Ryan
Krzysztof : you are my hero :)unfortunately i can't vote at the time being.i would vote for 15.
Nour Sabouny