User: xtoff
Date: 2009/12/23 01:39 PM
Added:
/InversionOfControl/trunk/src/Castle.MicroKernel/Facilities/TypedFactory/
TypedFactoryComponent.cs
/InversionOfControl/trunk/src/Castle.Windsor.Tests/Facilities/TypedFactory/Components/
DisposableComponent.cs, GenericComponent.cs, GenericComponentWithIntArg.cs
/InversionOfControl/trunk/src/Castle.Windsor.Tests/Facilities/TypedFactory/Factories/
DummyComponentFactory.cs, IDisposableFactory.cs, IGenericComponentsFactory.cs
Modified:
/InversionOfControl/trunk/src/Castle.MicroKernel/
Castle.MicroKernel-vs2008.csproj
/InversionOfControl/trunk/src/Castle.MicroKernel/Facilities/TypedFactory/
DefaultTypedFactoryComponentSelector.cs, ITypedFactoryComponentSelector.cs,
Resolve.cs, TypedFactoryInterceptor.cs
/InversionOfControl/trunk/src/Castle.Windsor.Tests/
Castle.Windsor.Tests-vs2008.csproj
/InversionOfControl/trunk/src/Castle.Windsor.Tests/Facilities/TypedFactory/
TypedFactoryFacilityTake2TestCase.cs
/InversionOfControl/trunk/src/Castle.Windsor/Proxy/
DefaultProxyFactory.cs
Log:
- Added support for resolving generic components via typed factory and for
resolving components via generic factory.
- Fixed bug with disposable factories
File Changes:
Directory: /InversionOfControl/trunk/src/Castle.MicroKernel/
============================================================
File [modified]: Castle.MicroKernel-vs2008.csproj
Delta lines: +26 -5
===================================================================
---
InversionOfControl/trunk/src/Castle.MicroKernel/Facilities/TypedFactory/DefaultTypedFactoryComponentSelector.cs
2009-12-23 17:11:42 UTC (rev 6529)
+++
InversionOfControl/trunk/src/Castle.MicroKernel/Facilities/TypedFactory/DefaultTypedFactoryComponentSelector.cs
2009-12-23 20:39:17 UTC (rev 6530)
@@ -15,22 +15,43 @@
namespace Castle.MicroKernel.Facilities.TypedFactory
{
using System;
+ using System.Collections.Generic;
using System.Reflection;
- using Castle.Core;
-
public class DefaultTypedFactoryComponentSelector :
ITypedFactoryComponentSelector
{
- public Pair<string, Type> SelectComponent(MethodInfo method,
Type type)
+ public TypedFactoryComponent SelectComponent(MethodInfo method,
Type type, object[] arguments)
{
+ var componentName = GetComponentName(method);
+ var componentType = GetComponentType(method);
+ var additionalArguments = GetArguments(method,
arguments);
+ return new TypedFactoryComponent(componentName,
componentType, additionalArguments);
+ }
+
+ private Type GetComponentType(MethodInfo method)
+ {
+ return method.ReturnType;
+ }
+
+ private string GetComponentName(MethodInfo method)
+ {
string componentName = null;
if (method.Name.StartsWith("Get"))
{
componentName =
method.Name.Substring("get".Length);
}
- var componentType = method.ReturnType;
+ return componentName;
+ }
- return new Pair<string,
Type>(componentName,componentType);
+ private Dictionary<string, object> GetArguments(MethodInfo
method, object[] arguments)
+ {
+ var argumentMap = new Dictionary<string, object>();
+ var parameters = method.GetParameters();
+ for (int i = 0; i < parameters.Length; i++)
+ {
+ argumentMap.Add(parameters[i].Name,
arguments[i]);
+ }
+ return argumentMap;
}
}
}
Directory: /InversionOfControl/trunk/src/Castle.Windsor.Tests/
==============================================================
File [modified]: Castle.Windsor.Tests-vs2008.csproj
Delta lines: +28 -0
===================================================================
---
InversionOfControl/trunk/src/Castle.Windsor.Tests/Facilities/TypedFactory/Components/DisposableComponent.cs
(rev 0)
+++
InversionOfControl/trunk/src/Castle.Windsor.Tests/Facilities/TypedFactory/Components/DisposableComponent.cs
2009-12-23 20:39:17 UTC (rev 6530)
@@ -0,0 +1,28 @@
+// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Castle.Facilities.TypedFactory.Tests.Components
+{
+ using System;
+
+ public class DisposableComponent:IDisposable
+ {
+ public void Dispose()
+ {
+ Disposed = true;
+ }
+
+ public bool Disposed { get; set; }
+ }
+}
Directory:
/InversionOfControl/trunk/src/Castle.Windsor.Tests/Facilities/TypedFactory/Components/
=================================================================================================
File [added]: DisposableComponent.cs
Delta lines: +21 -0
===================================================================
---
InversionOfControl/trunk/src/Castle.Windsor.Tests/Facilities/TypedFactory/Components/GenericComponent.cs
(rev 0)
+++
InversionOfControl/trunk/src/Castle.Windsor.Tests/Facilities/TypedFactory/Components/GenericComponent.cs
2009-12-23 20:39:17 UTC (rev 6530)
@@ -0,0 +1,21 @@
+// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Castle.Facilities.TypedFactory.Tests.Components
+{
+ public class GenericComponent<T>
+ {
+ public T Value { get; set; }
+ }
+}
File [added]: GenericComponent.cs
Delta lines: +28 -0
===================================================================
---
InversionOfControl/trunk/src/Castle.Windsor.Tests/Facilities/TypedFactory/Components/GenericComponentWithIntArg.cs
(rev 0)
+++
InversionOfControl/trunk/src/Castle.Windsor.Tests/Facilities/TypedFactory/Components/GenericComponentWithIntArg.cs
2009-12-23 20:39:17 UTC (rev 6530)
@@ -0,0 +1,28 @@
+// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Castle.Facilities.TypedFactory.Tests.Components
+{
+ public class GenericComponentWithIntArg<T>
+ {
+ public GenericComponentWithIntArg(int arg)
+ {
+ Property = arg;
+ }
+
+ public int Property { get; private set; }
+
+ public T Value { get; set; }
+ }
+}
File [added]: GenericComponentWithIntArg.cs
Delta lines: +24 -0
===================================================================
---
InversionOfControl/trunk/src/Castle.Windsor.Tests/Facilities/TypedFactory/Factories/DummyComponentFactory.cs
(rev 0)
+++
InversionOfControl/trunk/src/Castle.Windsor.Tests/Facilities/TypedFactory/Factories/DummyComponentFactory.cs
2009-12-23 20:39:17 UTC (rev 6530)
@@ -0,0 +1,24 @@
+// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Castle.Windsor.Tests.Facilities.TypedFactory.Factories
+{
+ using Castle.Facilities.TypedFactory.Tests.Components;
+
+ public interface DummyComponentFactory
+ {
+ IDummyComponent CreateDummyComponent();
+ IDummyComponent GetSecondComponent();
+ }
+}
Directory:
/InversionOfControl/trunk/src/Castle.Windsor.Tests/Facilities/TypedFactory/Factories/
================================================================================================
File [added]: DummyComponentFactory.cs
Delta lines: +27 -0
===================================================================
---
InversionOfControl/trunk/src/Castle.Windsor.Tests/Facilities/TypedFactory/Factories/IDisposableFactory.cs
(rev 0)
+++
InversionOfControl/trunk/src/Castle.Windsor.Tests/Facilities/TypedFactory/Factories/IDisposableFactory.cs
2009-12-23 20:39:17 UTC (rev 6530)
@@ -0,0 +1,27 @@
+// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Castle.Windsor.Tests.Facilities.TypedFactory.Factories
+{
+ using System;
+
+ using Castle.Facilities.TypedFactory.Tests.Components;
+
+ public interface IDisposableFactory : IDisposable
+ {
+ DisposableComponent Create();
+
+ void Destroy(DisposableComponent value);
+ }
+}
File [added]: IDisposableFactory.cs
Delta lines: +23 -0
===================================================================
---
InversionOfControl/trunk/src/Castle.Windsor.Tests/Facilities/TypedFactory/Factories/IGenericComponentsFactory.cs
(rev 0)
+++
InversionOfControl/trunk/src/Castle.Windsor.Tests/Facilities/TypedFactory/Factories/IGenericComponentsFactory.cs
2009-12-23 20:39:17 UTC (rev 6530)
@@ -0,0 +1,23 @@
+// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Castle.Facilities.TypedFactory.Tests.Factories
+{
+ public interface IGenericComponentsFactory
+ {
+ T CreateGeneric<T>();
+
+ T CreateGeneric<T, A>(A arg);
+ }
+}
File [added]: IGenericComponentsFactory.cs
Delta lines: +60 -7
===================================================================
---
InversionOfControl/trunk/src/Castle.Windsor.Tests/Facilities/TypedFactory/TypedFactoryFacilityTake2TestCase.cs
2009-12-23 17:11:42 UTC (rev 6529)
+++
InversionOfControl/trunk/src/Castle.Windsor.Tests/Facilities/TypedFactory/TypedFactoryFacilityTake2TestCase.cs
2009-12-23 20:39:17 UTC (rev 6530)
@@ -19,9 +19,12 @@
using Castle.Core;
using Castle.Facilities.TypedFactory.Tests.Components;
+ using Castle.Facilities.TypedFactory.Tests.Factories;
using Castle.MicroKernel.Facilities.TypedFactory;
using Castle.MicroKernel.Registration;
+ using Castle.MicroKernel.Resolvers.SpecializedResolvers;
using Castle.Windsor;
+ using Castle.Windsor.Tests.Facilities.TypedFactory.Factories;
using NUnit.Framework;
@@ -85,19 +88,69 @@
component = factory.CreateDummyComponent();
Assert.IsInstanceOf<Component2>(component);
}
- }
- public interface DummyComponentFactory
- {
- IDummyComponent CreateDummyComponent();
- IDummyComponent GetSecondComponent();
+ [Test]
+ public void Can_resolve_open_generic_components()
+ {
+ container.Register(
+
Component.For<IGenericComponentsFactory>().AsFactory(),
+
Component.For(typeof(GenericComponentWithIntArg<>)).LifeStyle.Singleton,
+
Component.For(typeof(GenericComponent<>)).LifeStyle.Singleton);
+
+ var factory =
container.Resolve<IGenericComponentsFactory>();
+
+ factory.CreateGeneric<GenericComponent<int>>();
+ factory.CreateGeneric<GenericComponent<IDisposable>>();
+
+ var component =
factory.CreateGeneric<GenericComponentWithIntArg<string>, int>(667);
+ Assert.AreEqual(667, component.Property);
+ }
+
+ [Test]
+ public void Can_resolve_via_generic_factory()
+ {
+ container.Register(
+
Component.For<IGenericComponentsFactory>().AsFactory());
+
+ var factory =
container.Resolve<IGenericComponentsFactory>();
+ var component =
factory.CreateGeneric<IDummyComponent>();
+ Assert.IsInstanceOf<Component1>(component);
+ }
+
+ [Test]
+ public void Disposing_factory_destroys_transient_components()
+ {
+ container.Register(
+ Component.For<IDisposableFactory>().AsFactory(),
+
Component.For<DisposableComponent>().LifeStyle.Transient);
+ var factory = container.Resolve<IDisposableFactory>();
+ var component = factory.Create();
+ Assert.IsFalse(component.Disposed);
+
+ factory.Dispose();
+ Assert.IsTrue(component.Disposed);
+ }
+
+ [Test]
+ public void
Disposing_factory_does_not_destroy_singleton_components()
+ {
+ container.Register(
+ Component.For<IDisposableFactory>().AsFactory(),
+
Component.For<DisposableComponent>().LifeStyle.Singleton);
+ var factory = container.Resolve<IDisposableFactory>();
+ var component = factory.Create();
+ Assert.IsFalse(component.Disposed);
+
+ factory.Dispose();
+ Assert.IsFalse(component.Disposed);
+ }
}
public class FooSelector:ITypedFactoryComponentSelector
{
- public Pair<string, Type> SelectComponent(MethodInfo method,
Type type)
+ public TypedFactoryComponent SelectComponent(MethodInfo method,
Type type, object[] arguments)
{
- return new Pair<string, Type>("foo", null);
+ return new TypedFactoryComponent("foo", null, null);
}
}
}
Directory: /InversionOfControl/trunk/src/Castle.Windsor/Proxy/
==============================================================
File [modified]: DefaultProxyFactory.cs
Delta lines: +6 -0
===================================================================
---
InversionOfControl/trunk/src/Castle.Windsor.Tests/Castle.Windsor.Tests-vs2008.csproj
2009-12-23 17:11:42 UTC (rev 6529)
+++
InversionOfControl/trunk/src/Castle.Windsor.Tests/Castle.Windsor.Tests-vs2008.csproj
2009-12-23 20:39:17 UTC (rev 6530)
@@ -276,12 +276,18 @@
<Compile Include="Facilities\Remoting\ServerClientContainerTestCase.cs" />
<Compile Include="Facilities\TypedFactory\Components\Component1.cs" />
<Compile Include="Facilities\TypedFactory\Components\Component2.cs" />
+ <Compile
Include="Facilities\TypedFactory\Components\DisposableComponent.cs" />
+ <Compile Include="Facilities\TypedFactory\Components\GenericComponent.cs"
/>
+ <Compile
Include="Facilities\TypedFactory\Components\GenericComponentWithIntArg.cs" />
<Compile Include="Facilities\TypedFactory\Components\IDummyComponent.cs" />
<Compile Include="Facilities\TypedFactory\Components\IProtocolHandler.cs"
/>
<Compile
Include="Facilities\TypedFactory\Components\MessengerProtocolHandler.cs" />
<Compile
Include="Facilities\TypedFactory\Components\MirandaProtocolHandler.cs" />
<Compile
Include="Facilities\TypedFactory\ExternalConfigurationTestCase.cs" />
+ <Compile Include="Facilities\TypedFactory\Factories\IDisposableFactory.cs"
/>
+ <Compile
Include="Facilities\TypedFactory\Factories\DummyComponentFactory.cs" />
<Compile Include="Facilities\TypedFactory\Factories\IComponentFactory.cs"
/>
+ <Compile
Include="Facilities\TypedFactory\Factories\IGenericComponentsFactory.cs" />
<Compile
Include="Facilities\TypedFactory\Factories\IProtocolHandlerFactory.cs" />
<Compile Include="Facilities\TypedFactory\TypedFactoryTestCase.cs" />
Directory:
/InversionOfControl/trunk/src/Castle.MicroKernel/Facilities/TypedFactory/
====================================================================================
File [modified]: DefaultTypedFactoryComponentSelector.cs
Delta lines: +5 -5
===================================================================
---
InversionOfControl/trunk/src/Castle.MicroKernel/Facilities/TypedFactory/ITypedFactoryComponentSelector.cs
2009-12-23 17:11:42 UTC (rev 6529)
+++
InversionOfControl/trunk/src/Castle.MicroKernel/Facilities/TypedFactory/ITypedFactoryComponentSelector.cs
2009-12-23 20:39:17 UTC (rev 6530)
@@ -17,21 +17,21 @@
using System;
using System.Reflection;
- using Castle.Core;
-
public interface ITypedFactoryComponentSelector
{
/// <summary>
/// Selects one or both of component name and type, for given
method
/// called on given typed factory type.
/// When component should be requested by type only,
- /// name (first argument of returned pair) should be null.
+ /// componentName should be null.
/// When component should be requested by name only,
- /// type (second argument of returned pair) should be null.
+ /// componentType should be null.
+ ///
/// </summary>
/// <param name="method"></param>
/// <param name="type"></param>
+ /// <param name="arguments"></param>
/// <returns></returns>
- Pair<string, Type> SelectComponent(MethodInfo method, Type
type);
+ TypedFactoryComponent SelectComponent(MethodInfo method, Type
type, object[] arguments);
}
}
File [modified]: ITypedFactoryComponentSelector.cs
Delta lines: +6 -20
===================================================================
---
InversionOfControl/trunk/src/Castle.MicroKernel/Facilities/TypedFactory/Resolve.cs
2009-12-23 17:11:42 UTC (rev 6529)
+++
InversionOfControl/trunk/src/Castle.MicroKernel/Facilities/TypedFactory/Resolve.cs
2009-12-23 20:39:17 UTC (rev 6530)
@@ -14,8 +14,6 @@
namespace Castle.MicroKernel.Facilities.TypedFactory
{
- using System.Collections.Generic;
-
using Castle.Core.Interceptor;
/// <summary>
@@ -33,32 +31,20 @@
public void Invoke(IInvocation invocation)
{
- var component =
selector.SelectComponent(invocation.Method, invocation.TargetType);
- var arguments = GetArguments(invocation);
- if (component.First == null)
+ var component =
selector.SelectComponent(invocation.Method, invocation.TargetType,
invocation.Arguments);
+ if (component.ComponentName == null)
{
- invocation.ReturnValue =
kernel.Resolve(component.Second, arguments);
+ invocation.ReturnValue =
kernel.Resolve(component.ComponentType, component.AdditionalArguments);
return;
}
- if (component.Second == null)
+ if (component.ComponentType == null)
{
- invocation.ReturnValue =
kernel.Resolve(component.First, arguments);
+ invocation.ReturnValue =
kernel.Resolve(component.ComponentName, component.AdditionalArguments);
return;
}
- invocation.ReturnValue =
kernel.Resolve(component.First, component.Second, arguments);
+ invocation.ReturnValue =
kernel.Resolve(component.ComponentName, component.ComponentType,
component.AdditionalArguments);
}
-
- private Dictionary<string, object> GetArguments(IInvocation
invocation)
- {
- var arguments = new Dictionary<string, object>();
- var parameters = invocation.Method.GetParameters();
- for (int i = 0; i < parameters.Length; i++)
- {
- arguments.Add(parameters[i].Name,
invocation.GetArgumentValue(i));
- }
- return arguments;
- }
}
}
File [modified]: Resolve.cs
Delta lines: +48 -0
===================================================================
---
InversionOfControl/trunk/src/Castle.MicroKernel/Facilities/TypedFactory/TypedFactoryComponent.cs
(rev 0)
+++
InversionOfControl/trunk/src/Castle.MicroKernel/Facilities/TypedFactory/TypedFactoryComponent.cs
2009-12-23 20:39:17 UTC (rev 6530)
@@ -0,0 +1,48 @@
+// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Castle.MicroKernel.Facilities.TypedFactory
+{
+ using System;
+ using System.Collections.Generic;
+
+ public class TypedFactoryComponent
+ {
+ private readonly Type componentType;
+ private readonly string componentName;
+ private readonly Dictionary<string, object> additionalArguments;
+
+ public TypedFactoryComponent(string componentName, Type
componentType, Dictionary<string, object> additionalArguments)
+ {
+ this.componentType = componentType;
+ this.componentName = componentName;
+ this.additionalArguments = additionalArguments ?? new
Dictionary<string, object>();
+ }
+
+ public Type ComponentType
+ {
+ get { return componentType; }
+ }
+
+ public string ComponentName
+ {
+ get { return componentName; }
+ }
+
+ public Dictionary<string, object> AdditionalArguments
+ {
+ get { return additionalArguments; }
+ }
+ }
+}
File [added]: TypedFactoryComponent.cs
Delta lines: +36 -16
===================================================================
---
InversionOfControl/trunk/src/Castle.MicroKernel/Facilities/TypedFactory/TypedFactoryInterceptor.cs
2009-12-23 17:11:42 UTC (rev 6529)
+++
InversionOfControl/trunk/src/Castle.MicroKernel/Facilities/TypedFactory/TypedFactoryInterceptor.cs
2009-12-23 20:39:17 UTC (rev 6530)
@@ -62,27 +62,42 @@
throw new ObjectDisposedException("this", "The
factory was disposed and can no longer be used.");
}
- var method = methods[invocation.Method];
+ ITypedFactoryMethod method;
+ if (TryGetMethod(invocation, out method) == false)
+ {
+ throw new Exception(
+ string.Format("Can't find information
about factory method {0}. This is most likely a bug. Please report it.",
+ invocation.Method));
+ }
method.Invoke(invocation);
}
+ private bool TryGetMethod(IInvocation invocation, out
ITypedFactoryMethod method)
+ {
+ if (methods.TryGetValue(invocation.Method, out method))
+ return true;
+ if (invocation.Method.IsGenericMethod == false)
+ return false;
+ return
methods.TryGetValue(invocation.Method.GetGenericMethodDefinition(), out method);
+ }
+
public void SetInterceptedComponentModel(ComponentModel target)
{
this.target = target;
- BuildHandlersMap();
+ BuildHandlersMap(this.target.Service);
}
- protected virtual void BuildHandlersMap()
+ protected virtual void BuildHandlersMap(Type service)
{
- MethodInfo dispose = GetDisposeMethod();
+ if(service.Equals(typeof(IDisposable)))
+ {
+ var method = service.GetMethods().Single();
+ methods.Add(method, new Dispose(Dispose));
+ return;
+ }
- foreach (MethodInfo method in
target.Service.GetMethods())
+ foreach (MethodInfo method in service.GetMethods())
{
- if (method == dispose)
- {
- methods.Add(method, new
Dispose(Dispose));
- continue;
- }
if (IsReleaseMethod(method))
{
methods.Add(method, new
Release(kernel));
@@ -91,18 +106,23 @@
//TODO: had collection handling
methods.Add(method, new Resolve(kernel,
ComponentSelector));
}
- }
- private MethodInfo GetDisposeMethod()
- {
- if
(!typeof(IDisposable).IsAssignableFrom(target.Service))
+ foreach (var @interface in service.GetInterfaces())
{
- return null;
+ BuildHandlersMap(@interface);
}
+ }
- return
target.Service.GetInterfaceMap(typeof(IDisposable)).TargetMethods.Single();
+ private bool IsDispose(MethodInfo method)
+ {
+ return method.Name.Equals("Disposable",
StringComparison.Ordinal) && method.GetParameters().Length == 0;
}
+ private bool GetIsDisposable()
+ {
+ return
typeof(IDisposable).IsAssignableFrom(target.Service);
+ }
+
private bool IsReleaseMethod(MethodInfo methodInfo)
{
File [modified]: TypedFactoryInterceptor.cs
Delta lines: +1 -1
===================================================================
--- InversionOfControl/trunk/src/Castle.Windsor/Proxy/DefaultProxyFactory.cs
2009-12-23 17:11:42 UTC (rev 6529)
+++ InversionOfControl/trunk/src/Castle.Windsor/Proxy/DefaultProxyFactory.cs
2009-12-23 20:39:17 UTC (rev 6530)
@@ -64,7 +64,7 @@
/// <param name="target">The target.</param>
/// <param name="model">The model.</param>
/// <param name="constructorArguments">The constructor
arguments.</param>
- /// <param name="context">The creation context</param>
+ /// <param name="context">The creation context</param>
/// <returns>The component proxy.</returns>
public override object Create(IKernel kernel, object target,
ComponentModel model, CreationContext context, params object[]
constructorArguments)
Directory:
/InversionOfControl/trunk/src/Castle.Windsor.Tests/Facilities/TypedFactory/
======================================================================================
File [modified]: TypedFactoryFacilityTake2TestCase.cs
Delta lines: +0 -0
===================================================================
--
You received this message because you are subscribed to the Google Groups
"Castle Project Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-commits?hl=en.