Home

Castle Stronghold

TypedFactory Facility

Given a factory interface, automatic implement it delegating creation to the container.

Facility Summary
Uses ProxyYes
Requires configurationYes
Uses attributeNo
VersionBeta 3
Maturity levelMedium

Introduction

This facility implements the factories you provide by interfaces. For example, suppose you have a family of related components implementing the service IProtocolHandler. Others components that want to use implementations of IProtocolHandler can use a factory for it. So you just need to create this factory interface and this facility implements it for you.

Quick start

This is an example of a factory interface. Please note that you may have a method for the disposal of the component too.


public interface IProtocolHandlerFactory
{
    IProtocolHandler Create( String id );
}

public interface IProtocolHandlerFactory2
{
    IProtocolHandler Create( String id );

    void Release( IProtocolHandler handler );
}    

The following configures the facility to implement the interfaces above.


<configuration>

  <facilities>
    <facility 
        id="typedfactory" 
        type="Castle.Facilities.TypedFactory.TypedFactoryFacility, Castle.MicroKernel">
        
        <factories>
        
            <factory id="compFactory1" 
                interface="Factories.IProtocolHandlerFactory, TypedFactory.Tests" 
                creation="Create" destruction="" />

            <factory id="protocolFac2" 
                interface="Factories.IProtocolHandlerFactory2, TypedFactory.Tests" 
                creation="Create" destruction="Release" />
        
        </factories>

    </facility>
  </facilities>

</configuration>

Required Assemblies

The facility is included in the Castle.MicroKernel assembly

Google
Search WWW Search castleproject.org