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
.Windsor
.Tests
18 using Castle
.MicroKernel
.Exceptions
;
19 using Castle
.MicroKernel
.Handlers
;
20 using Castle
.Windsor
.Tests
.Components
;
21 using NUnit
.Framework
;
24 public class CircularDependencyTests
27 public void ShouldNotSetTheViewControllerProperty()
29 IWindsorContainer container
= new WindsorContainer();
30 container
.AddComponent("controller", typeof(IController
), typeof(Controller
));
31 container
.AddComponent("view", typeof(IView
), typeof(View
));
32 Controller controller
= (Controller
)container
.Resolve("controller");
33 Assert
.IsNotNull(controller
.View
);
34 Assert
.IsNull(controller
.View
.Controller
);
39 ExpectedException(typeof(HandlerException
),
40 @"Can't create component 'compA' as it has dependencies to be satisfied.
41 compA is waiting for the following dependencies:
44 - Castle.Windsor.Tests.Components.CompB which was registered but is also waiting for dependencies.
46 compB is waiting for the following dependencies:
49 - Castle.Windsor.Tests.Components.CompC which was registered but is also waiting for dependencies.
51 compC is waiting for the following dependencies:
54 - Castle.Windsor.Tests.Components.CompD which was registered but is also waiting for dependencies.
56 compD is waiting for the following dependencies:
59 - Castle.Windsor.Tests.Components.CompA which was registered but is also waiting for dependencies.
62 public void ThrowsACircularDependencyException2()
64 IWindsorContainer container
= new WindsorContainer();
65 container
.AddComponent("compA", typeof(CompA
));
66 container
.AddComponent("compB", typeof(CompB
));
67 container
.AddComponent("compC", typeof(CompC
));
68 container
.AddComponent("compD", typeof(CompD
));
70 container
.Resolve("compA");
74 public void ShouldNotGetCircularDepencyExceptionWhenResolvingTypeOnItselfWithDifferentModels()
76 WindsorContainer container
= new WindsorContainer(ConfigHelper
.ResolveConfigPath("IOC-51.xml"));
77 object o
= container
["path.fileFinder"];
84 using System
.Reflection
;
86 public interface IPathProvider
91 public class AssemblyPath
: IPathProvider
97 Uri uriPath
= new Uri(Assembly
.GetExecutingAssembly().GetName(false).CodeBase
);
98 return uriPath
.LocalPath
;
103 public class RelativeFilePath
: IPathProvider
105 public RelativeFilePath(IPathProvider basePathProvider
, string extensionsPath
)
107 _path
= System
.IO
.Path
.Combine(basePathProvider
.Path
+ "\\", extensionsPath
);
112 get { return _path; }
115 private string _path
;