Dashboard > GreenPepper Open Documentation Refactoring > ... > 8. Developer examples > Windsor Castle System Under Development
  GreenPepper Open Documentation Refactoring Log In View a printable version of the current page.  
  Windsor Castle System Under Development
Added by Laurent Cobos, last edited by Laurent Cobos on Aug 13, 2009  (view change)
Labels: 
(None)

The Windsor castle container system under development

Windsor container is an Inversion Of Control (IOC) container get more information about it on Windsor Castle website

New in GreenPepper .Net 1.3
Import
GreenPepper.WindsorCastle.Fixtures


A Castle basic Xml configuration file
<configuration>
    <components>
        <component id="Windsor.HelloWorld" type="GreenPepper.WindsorCastle.Fixtures.WindsorHelloWorld, GreenPepper.Extensions">
            <parameters>
            	<injectedConstructor>hello constructor</injectedConstructor>
                <injectedProperty>hello property</injectedProperty>
            </parameters>
        </component>

        <component id="Windsor.component1" 
        	type="GreenPepper.WindsorCastle.Fixtures.MyComponent1, GreenPepper.Extensions">
        </component>
        
        <component id="Windsor.component2"
        	type="GreenPepper.WindsorCastle.Fixtures.MyComponent2, GreenPepper.Extensions">
        </component>
        
        <component id="Windsor.AutoWired" type="GreenPepper.WindsorCastle.Fixtures.WindsorAutoWiredFixture, GreenPepper.Extensions" />
    </components>
</configuration>
How to use Windsor system under development :
Begin Info
  • Requirements :
  1. You must add GreenPepper.Extensions.Castle.Windsor assembly in your configuration assemblies
  2. You must notify GreenPepper Core to use Windsor system under development : GreenPepper.WindsorCastle.WindsorSystemUnderDevelopment

(You can find more about system under development configuration here : Using a custom SystemUnderDevelopment)

  • If you use a Windsor xml configuration file :
    Just add the path to your Windsor configuration file in the system under development arguments
End Info
WindsorCastle system under development
using System;
using Castle.MicroKernel;
using Castle.Windsor;
using GreenPepper.Fixtures;
using GreenPepper.Reflect;

namespace GreenPepper.WindsorCastle
{
    public class WindsorSystemUnderDevelopment : PlainOldSystemUnderDevelopment
    {
        private IWindsorContainer container;

        public WindsorSystemUnderDevelopment(IWindsorContainer container)
        {
            this.container = container;
        }

        public WindsorSystemUnderDevelopment():this(new WindsorContainer())
        {    
        }

        public WindsorSystemUnderDevelopment(params string[] xmlConfigurationFile)
            : this(new WindsorContainer(xmlConfigurationFile[0]))
        {
        }

        public override IFixture GetFixture(string fixtureName, params string[] parameters)
        {
            try
            {
                Type type = TypeForName(fixtureName);
                container.AddComponent(type.FullName, type);
                return new DefaultFixture(container.Resolve(type));
            }
            catch (Exception)
            {
                try
                {
                    return new DefaultFixture(container.Resolve(fixtureName));   
                }
                catch (ComponentNotFoundException)
                {
                    return base.GetFixture(fixtureName, parameters);
                }
            }
        }
    }
}

DEMONSTRATION LICENSE - This Confluence site is for demonstration purposes only. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.4.3 Build:#705 Mar 21, 2007) - Bug/feature request - Contact Administrators