1 // Copyright 2004-2007 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.
15 namespace Castle
.Facilities
.FactorySupport
.Tests
17 using System
.Collections
.Generic
;
18 using Castle
.MicroKernel
;
19 using NUnit
.Framework
;
22 public class FactorySupportProgrammaticTestCase
24 private IKernel kernel
;
25 private FactorySupportFacility facility
;
30 facility
= new FactorySupportFacility();
31 kernel
= new DefaultKernel();
35 public void FactoryResolveWithProposedFacilityPatch()
37 kernel
.AddFacility("factory.support", facility
);
39 string serviceKey
= "someService";
40 facility
.AddFactory
<ISomeService
, ServiceFactory
>(serviceKey
, "Create");
42 ISomeService service
= kernel
.Resolve(serviceKey
,
43 typeof(ISomeService
)) as ISomeService
;
45 Assert
.IsTrue(ServiceFactory
.CreateWasCalled
);
46 Assert
.IsInstanceOfType(typeof(ServiceImplementation
), service
);
50 #region Exampleclasses
52 public interface ISomeService
57 public class ServiceImplementation
: ISomeService
59 private int _someValue
;
63 get { return _someValue; }
64 set { _someValue = value; }
67 public ServiceImplementation(int someValue
)
69 _someValue
= someValue
;
72 public void SomeOperation()
77 public class ServiceFactory
79 public static bool CreateWasCalled
;
81 public ServiceImplementation
Create()
83 CreateWasCalled
= true;
84 return new ServiceImplementation(12);