views:

226

answers:

1

I would like to use "strategy pattern" with 2 Web projects, my configuration file (and only with configuration file) :

<?xml version="1.0"?>
<configuration>
    <components>
      <!-- container ORM -->
      <component id="DALReseauContainer"  type="ReseauRules.Db.BLL.DbReseauWorkingContextContainer, ReseauRules"                       service="ReseauConnector.BLL.IReseauWorkingContextContainer, ReseauConnector">        
      </component>

      <!-- remote controler (Web Service) -->
      <component id="remoteReseauManager"
                 type="ReseauConnector.BLL.RemoteReseauManager, ReseauConnector"
                 service="ReseauConnector.BLL.IReseauManager, ReseauConnector"
                 lifestyle="transient">        
      </component>

      <!-- local controler  -->
      <component id="localReseauManager"
                 type="ReseauRules.Db.BLL.DbReseauManager, ReseauRules"
                 service="ReseauConnector.BLL.IReseauManager, ReseauConnector"
                 lifestyle="transient">
        <parameters>
          <container>${DALReseauContainer}</container>
        </parameters>
      </component>
    </components>
</configuration>

project A uses "remoteReseauManager" and references only ReseauConnector, can call

container.Resolve<IReseauManager>("remoteReseauManager");

project B uses "localReseauManager" and references ReseauConnector AND ReseauRules, can call

container.Resolve<IReseauManager>("localReseauManager");

when I call

IWindsorContainer container = new WindsorContainer(new Castle.Windsor.Configuration.Interpreters.XmlInterpreter()); 

Windsor tries to resolve each components, and as in project A,ReseauRules does not exist, Windsor can't load ReseauRules (as expected).

How to tell to Windsor do not load a component in this context (configuration file) ?

Thanks a lot.

A: 

You are supposed to have one container per application, so in this case it would also make most sense to have a Windsor configuration per application. Obviously, the two applications have different depedency requirements.

Each application must already have its own web.config, so have separate Windsor configurations in each.

If maintainability is an issue, XML is not the solution in any case. If you have a lot of shared container configuration, write an IWindsorInstaller implementation and only keep the parts of the configurations that are different in XML.

You can mix XML configuration and configuration as code.

Mark Seemann
thanksbut each applications (ie : in each web.config) can have the same castle configuration file, defined in <castle><include uri="file://d:\config\IoC\Reseauomponents.config" /> </castle>I'll study an IWindsorInstaller implementation
Olivier DUVAL
Yes, I understood that, but my point is that this doesn't make your life easier - it makes it harder.
Mark Seemann