Allow component registration specification of LifeStyle using LifeStyleType.
[castle.git] / InversionOfControl / Castle.MicroKernel.Tests / SubResolverTestCase.cs
blob2c766bf125ed1f916bef34b19f6ab8c5980a6126
1 // Copyright 2004-2008 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.MicroKernel.Tests
17 using Core;
18 using NUnit.Framework;
20 [TestFixture]
21 public class SubResolverTestCase
23 [Test]
24 public void WillAskResolverWhenTryingToResolveDependencyAfterAnotherHandlerWasRegistered()
26 FooBarResolver resolver = new FooBarResolver();
28 IKernel kernel = new DefaultKernel();
29 kernel.Resolver.AddSubResolver(resolver);
31 kernel.AddComponent("foo", typeof(Foo));
32 IHandler handler = kernel.GetHandler("foo");
33 Assert.AreEqual(HandlerState.WaitingDependency, handler.CurrentState);
35 resolver.Result = 15;
37 kernel.RaiseHandlerRegistered(null);//should force reevaluation of state
39 Assert.AreEqual(HandlerState.Valid, handler.CurrentState);
43 public class Foo
45 private int bar;
47 public Foo(int bar)
49 this.bar = bar;
53 public class FooBarResolver : ISubDependencyResolver
55 public int? Result;
57 public object Resolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model,
58 DependencyModel dependency)
60 return Result.Value;
63 public bool CanResolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model,
64 DependencyModel dependency)
66 return Result != null;