1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 namespace Castle
.Windsor
.Tests
.Proxy
18 using Castle
.Core
.Configuration
;
19 using Castle
.Core
.Interceptor
;
20 using Castle
.Facilities
.FactorySupport
;
21 using Castle
.Windsor
.Tests
.Components
;
22 using NUnit
.Framework
;
25 public class FactorySupportTestCase
27 private WindsorContainer container
;
32 container
= new WindsorContainer();
36 public void FactorySupport_UsingProxiedFactory_WorksFine()
38 container
.AddFacility("factories", new FactorySupportFacility());
39 container
.AddComponent("standard.interceptor", typeof(StandardInterceptor
));
40 container
.AddComponent("factory", typeof(CalulcatorFactory
));
42 AddComponent("calculator", typeof(ICalcService
), typeof(CalculatorService
), "Create");
44 ICalcService service
= (ICalcService
) container
["calculator"];
46 Assert
.IsNotNull(service
);
49 private void AddComponent(string key
, Type service
, Type type
, string factoryMethod
)
51 MutableConfiguration config
= new MutableConfiguration(key
);
52 config
.Attributes
["factoryId"] = "factory";
53 config
.Attributes
["factoryCreate"] = factoryMethod
;
54 container
.Kernel
.ConfigurationStore
.AddComponentConfiguration(key
, config
);
55 container
.Kernel
.AddComponent(key
, service
, type
);
58 [Interceptor(typeof(StandardInterceptor
))]
59 public class CalulcatorFactory
61 public virtual ICalcService
Create()
63 return new CalculatorService();