摘要:FactorySupport Facility允许我们使用已经存在的工厂来创建组件的实例,可以把已经存在的对象模型加入到容器中,以便它能够使用自动装配。它使用了以下两种处理策略:
2
.为什么需要FactorySupport Facility
FactorySupport Facility
允许我们使用已经存在的工厂来创建组件的实例,可以把已经存在的对象模型加入到容器中,以便它能够使用自动装配。它使用了以下两种处理策略:
二.为什么需要FactorySupport Facility
为了回答这个问题,我们先来看一个简单的使用工厂的例子,如下代码所示:
public
interface
IComponent
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
{
void Display();
}
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
public
class
MyComponent : IComponent
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
{
public MyComponent()
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public void Display()
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
Console.WriteLine("MyComponent![dot.gif](http://terrylee.cnblogs.com/Images/dot.gif)
");
}
}
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
public
class
MyFactory
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
{
public MyFactory()
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public IComponent Create()
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
return new MyComponent();
}
}
现在要在程序中使用
MyComponent的实例,简单一点会这样去写:
public
class
App
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
{
static void Main()
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
MyFactory factory = new MyFactory();
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
IComponent comp = factory.Create();
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
comp.Display();
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
}
正如你所看到的,在程序中使用
new关键字创建了一个工厂的实例,再由工厂得到组件的实例。现在我们看使用
FactorySupport Facility后带来了什么好处。工厂和组件的代码不变,仍然是:
public
interface
IComponent
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
{
void Display();
}
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
public
class
MyComponent : IComponent
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
{
public MyComponent()
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public void Display()
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
Console.WriteLine("MyComponent![dot.gif](http://terrylee.cnblogs.com/Images/dot.gif)
");
}
}
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
public
class
MyFactory
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
{
public MyFactory()
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public IComponent Create()
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
return new MyComponent();
}
}
配置文件,现在你可以不用理解怎么去配置,后面会讲到。
<?
xml version="1.0" encoding="utf-8"
?>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
configuration
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
facilities
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
facility
id
="factorysupport"
type
="Castle.Facilities.FactorySupport.FactorySupportFacility, Castle.MicroKernel"
/>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
facilities
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
components
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
component
id
="myfactory"
type
="FactorySupportDemo.MyFactory,FactorySupportDemo"
/>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
component
id
="mycomp"
type
="FactorySupportDemo.MyComponent,FactorySupportDemo"
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
factoryId
="myfactory"
factoryCreate
="Create"
></
component
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
components
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
configuration
>
public
class
App
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
{
static void Main()
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
IWindsorContainer container = new WindsorContainer("../../Basic.xml");
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
IComponent instance = (IComponent) container["mycomp"];
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
instance.Display();
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
}
看到了吗?我们并没有使用
new关键字创建任何对象,只是把工厂、组件等通过配置文件抛给了
IOC容器,再从容器中往外取的时候,就可以直接取到组件的实例,这些实例是由工厂自动创建的,这正是
FactorySupport Facility的作用。
知道了为什么需要FactorySupport Facility之后,下面就来看如何使用Facility。在前面的代码中大家都已经看到了,使用FactorySupport Facility是非常的简单。
1
.加入FactorySupport Facility到容器中,可以使用代码加入也可以使用配置文件。
使用代码加入:
IWindsorContainer container
=
new
WindsorContainer(
"
../../Basic.xml
"
);
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
container.AddFacility(
"
factorysupport
"
,
new
Castle.Facilities.FactorySupport.FactorySupportFacility());
使用配置文件:
<
facilities
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
facility
id
="factorysupport"
type
="Castle.Facilities.FactorySupport.FactorySupportFacility, Castle.MicroKernel"
/>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
facilities
>
如果使用访问器只需要指定访问器的名称就可以了:
<
component
id
="accessor.comp"
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
type
="Castle.Facilities.FactorySupport.Tests.Components.SingletonWithAccessor, Castle.Facilities.FactorySupport.Tests"
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
instance-accessor
="Instance"
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
component
>
如果使用工厂方法,需要指定工厂
ID和工厂方法:
<
component
id
="mycomp"
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
type
="Castle.Facilities.FactorySupport.Tests.Components.MyComp, Castle.Facilities.FactorySupport.Tests"
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
factoryId
="mycompfactory"
factoryCreate
="Create"
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
component
>
这是一些常见的配置示例,来自于Castle自带的测试代码中。
有这样一个单件类
public
class
SingletonWithAccessor
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
{
private static readonly SingletonWithAccessor instance = new SingletonWithAccessor();
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private SingletonWithAccessor()
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public static SingletonWithAccessor Instance
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
get { return instance; }
}
}
<?
xml version="1.0" encoding="utf-8"
?>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
configuration
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
facilities
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
facility
id
="factorysupport"
type
="Castle.Facilities.FactorySupport.FactorySupportFacility, Castle.MicroKernel"
/>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
facilities
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
components
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
component
id
="accessor.comp"
type
="Castle.Facilities.FactorySupport.Tests.Components.SingletonWithAccessor, Castle.Facilities.FactorySupport.Tests"
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
instance-accessor
="Instance"
></
component
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
components
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
configuration
>
public
class
MyComp
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
{
public MyComp()
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
}
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
public
class
MyCompFactory
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
{
public MyComp Create()
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
return new MyComp();
}
}
<?
xml version="1.0" encoding="utf-8"
?>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
configuration
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
facilities
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
facility
id
="factorysupport"
type
="Castle.Facilities.FactorySupport.FactorySupportFacility, Castle.MicroKernel"
/>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
facilities
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
components
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
component
id
="mycompfactory"
type
="Castle.Facilities.FactorySupport.Tests.Components.MyCompFactory, Castle.Facilities.FactorySupport.Tests"
/>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
component
id
="mycomp"
type
="Castle.Facilities.FactorySupport.Tests.Components.MyComp, Castle.Facilities.FactorySupport.Tests"
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
factoryId
="mycompfactory"
factoryCreate
="Create"
></
component
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
components
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
configuration
>
public
class
MyComp
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
{
private string storeName;
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private IDictionary props;
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
internal MyComp()
{
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
internal MyComp(String storeName, IDictionary props)
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
this.storeName = storeName;
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
this.props = props;
}
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public string StoreName
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
get { return storeName; }
}
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public IDictionary Props
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
get { return props; }
}
}
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
public
class
MyCompFactory2
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
{
public MyCompFactory2()
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public MyComp Create(String storeName, IDictionary props)
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
return new MyComp(storeName, props);
}
}
<?
xml version="1.0" encoding="utf-8"
?>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
configuration
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
facilities
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
facility
id
="factorysupport"
type
="Castle.Facilities.FactorySupport.FactorySupportFacility, Castle.MicroKernel"
/>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
facilities
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
components
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
component
id
="mycompfactory"
type
="Castle.Facilities.FactorySupport.Tests.Components.MyCompFactory2, Castle.Facilities.FactorySupport.Tests"
></
component
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
component
id
="mycomp"
type
="Castle.Facilities.FactorySupport.Tests.Components.MyComp, Castle.Facilities.FactorySupport.Tests"
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
factoryId
="mycompfactory"
factoryCreate
="Create"
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
parameters
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
storeName
>
MyStore
</
storeName
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
props
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
dictionary
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
entry
key
="key1"
>
item1
</
entry
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
entry
key
="key2"
>
item2
</
entry
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
dictionary
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
props
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
parameters
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
component
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
components
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
configuration
>
public
interface
IMyService
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
{
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
public
class
MyComp
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
{
private IMyService serv;
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
internal MyComp()
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
internal MyComp(IMyService serv)
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
this.serv = serv;
}
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public IMyService Service
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
get { return serv; }
}
}
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
public
class
MyCompFactory3
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
{
public MyCompFactory3()
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public MyComp Create(IMyService serv)
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
{
return new MyComp(serv);
}
}
<?
xml version="1.0" encoding="utf-8"
?>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
configuration
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
facilities
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
facility
id
="factorysupport"
type
="Castle.Facilities.FactorySupport.FactorySupportFacility, Castle.MicroKernel"
/>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
facilities
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
components
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
component
id
="myserv"
service
="Castle.Facilities.FactorySupport.Tests.Components.IMyService, Castle.Facilities.FactorySupport.Tests"
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
type
="Castle.Facilities.FactorySupport.Tests.Components.DefaultMyService, Castle.Facilities.FactorySupport.Tests"
/>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
component
id
="mycompfactory"
type
="Castle.Facilities.FactorySupport.Tests.Components.MyCompFactory3, Castle.Facilities.FactorySupport.Tests"
></
component
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<
component
id
="mycomp"
type
="Castle.Facilities.FactorySupport.Tests.Components.MyComp, Castle.Facilities.FactorySupport.Tests"
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
factoryId
="mycompfactory"
factoryCreate
="Create"
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
<!--
parameters is not necessary_u97 ?s it will auto wire
-->
</
component
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
components
>
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
</
configuration
>
FactorySupport Facility
的实现也是非常的简单,主要是通过两个
ComponentActivator
来实现,分别为AccessorActivator和FactoryActivator,根据配置文件的不同调用不同的Activator。
String instanceAccessor
=
model.Configuration.Attributes[
"
instance-accessor
"
];
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
String factoryId
=
model.Configuration.Attributes[
"
factoryId
"
];
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
String factoryCreate
=
model.Configuration.Attributes[
"
factoryCreate
"
];
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
if
(instanceAccessor
!=
null
)
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
{
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
model.ExtendedProperties.Add( "instance.accessor", instanceAccessor );
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
model.CustomComponentActivator = typeof(AccessorActivator);
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
else
if
(factoryId
!=
null
)
![None.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
{
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
model.ExtendedProperties.Add( "factoryId", factoryId );
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
model.ExtendedProperties.Add( "factoryCreate", factoryCreate );
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
model.CustomComponentActivator = typeof(FactoryActivator);
![InBlock.gif](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
好了,关于
FactorySupport Facility就介绍到这儿,更多
Castle的文章您可以访问《
Castle 开发系列文章》。
本文转自lihuijun51CTO博客,原文链接:
http://blog.51cto.com/terrylee/67692
,如需转载请自行联系原作者