Fixing previous commit, using correct case for CaptureFor and removing the component...
[castle.git] / InversionOfControl / Castle.Windsor.Tests / ContainerProblem2.cs
blob98bfac6bf7b7155e496b0fcb5aee3b9faa02abf2
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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.Windsor.Tests
17 using Castle.Core;
18 using NUnit.Framework;
20 [PerThread]
21 public class R
25 public interface IC
27 IN N { get; set; }
30 public class C : IC
32 private R _r = null;
34 public R R
36 set { _r = value; }
39 private IN _n = null;
41 public IN N
43 get { return _n; }
44 set { _n = value; }
48 public interface IN
50 IS CS { get; }
53 [Transient]
54 public class DN : IN
56 private IS _s = null;
57 private IWM _vm = null;
58 private ISP _sp = null;
60 public IS CS
62 get { return _s; }
65 public DN(IWM vm, ISP sp)
67 _vm = vm;
68 _sp = sp;
69 _s = new BS();
73 public interface IWM
75 void A(IN n);
78 public class WM : IWM
80 public void A(IN n)
82 //...
86 public interface IS
88 ISP SP { get; set; }
91 [Transient]
92 public class BS : IS
94 private ISP _sp = null;
96 public ISP SP
98 get { return _sp; }
99 set { _sp = value; }
103 public interface ISP
105 void Save(IS s);
108 public class SP : ISP
110 public void Save(IS s)
115 [TestFixture]
116 public class ContainerProblem2
118 [Test]
119 public void CausesStackOverflow()
121 IWindsorContainer container = new WindsorContainer();
123 container.AddComponent("BS", typeof(IS), typeof(BS));
124 container.AddComponent("C", typeof(IC), typeof(C));
125 container.AddComponent("WM", typeof(IWM), typeof(WM));
126 container.AddComponent("SP", typeof(ISP), typeof(SP));
128 // ComponentModel model = new ComponentModel("R", typeof(R), typeof(R));
129 // model.LifestyleType = LifestyleType.Custom;
130 // model.CustomLifestyle = typeof(PerThreadLifestyleManager);
132 // container.Kernel.AddCustomComponent(model);
133 // container.Kernel.AddComponent("R", typeof(R), LifestyleType.Thread);
134 container.Kernel.AddComponent("R", typeof(R));
136 IC c = container["C"] as IC;
137 Assert.IsNotNull(c);