User: jonathon.rossi
Date: 2010/01/13 02:57 AM
Modified:
/InversionOfControl/trunk/src/Castle.MicroKernel.Tests/Facilities/FactorySupport/
FactorySupportFluentTestCase.cs, FactorySupportProgrammaticTestCase.cs,
FactorySupportTestCase.cs
/InversionOfControl/trunk/src/Castle.MicroKernel/Facilities/FactorySupport/
AccessorActivator.cs, FactoryActivator.cs, FactorySupportFacility.cs
Log:
Reverted Krzysztof's changes in r6595, r6596 and r6653 to the factory support
facility (I kept the formatting clean up changes).
File Changes:
Directory:
/InversionOfControl/trunk/src/Castle.MicroKernel/Facilities/FactorySupport/
======================================================================================
File [modified]: AccessorActivator.cs
Delta lines: +10 -24
===================================================================
---
InversionOfControl/trunk/src/Castle.MicroKernel/Facilities/FactorySupport/FactoryActivator.cs
2010-01-13 07:01:56 UTC (rev 6653)
+++
InversionOfControl/trunk/src/Castle.MicroKernel/Facilities/FactorySupport/FactoryActivator.cs
2010-01-13 09:57:28 UTC (rev 6654)
@@ -60,12 +60,9 @@
factoryType.GetMethod(factoryCreate,
BindingFlags.Public |
BindingFlags.Static);
- object instance;
- string createMethodName;
if (staticCreateMethod != null)
{
- createMethodName =
staticCreateMethod.ToString();
- instance = this.Create(null, factoryId,
staticCreateMethod, factoryCreate, context);
+ return Create(null, factoryId,
staticCreateMethod, factoryCreate, context);
}
else
{
@@ -84,31 +81,20 @@
BindingFlags.Public |
BindingFlags.Instance);
}
- if (instanceCreateMethod == null)
+ if (instanceCreateMethod != null)
{
+ return Create(factoryInstance,
factoryId, instanceCreateMethod, factoryCreate, context);
+ }
+ else
+ {
String message = String.Format("You
have specified a factory " +
-
"('{2}' - method to be called: {3}) " +
-
"for the component '{0}' {1} but we couldn't find the
creation method" +
-
"(neither instance or static method with the name
'{3}')",
-
this.Model.Name, this.Model.Implementation.FullName,
factoryId, factoryCreate);
+ "('{2}'
- method to be called: {3}) " +
+ "for the
component '{0}' {1} but we couldn't find the creation method" +
+
"(neither instance or static method with the name '{3}')",
+
Model.Name, Model.Implementation.FullName, factoryId, factoryCreate);
throw new FacilityException(message);
}
-
- createMethodName =
instanceCreateMethod.ToString();
- instance = this.Create(factoryInstance,
factoryId, instanceCreateMethod, factoryCreate, context);
}
- var type =
context.Handler.ComponentModel.Implementation;
- if (instance != null && type != null &&
Model.Implementation.IsInstanceOfType(instance) == false)
- {
- String message =
- String.Format(
- "Factory '{0}' (method '{1}')
created instance of type {2}.{5}" +
- "This type is not compatible
with implementation type {3} registered for this component ({4}).{5}" +
- "This may signify a bug. If
it's the expected behavior, change the registration of this component to cover
this return type.",
- factoryId, createMethodName,
instance.GetType().FullName, type.FullName,
context.Handler.ComponentModel.Name, Environment.NewLine);
- throw new FacilityException(message);
- }
- return instance;
}
File [modified]: FactoryActivator.cs
Delta lines: +1 -1
===================================================================
---
InversionOfControl/trunk/src/Castle.MicroKernel/Facilities/FactorySupport/FactorySupportFacility.cs
2010-01-13 07:01:56 UTC (rev 6653)
+++
InversionOfControl/trunk/src/Castle.MicroKernel/Facilities/FactorySupport/FactorySupportFacility.cs
2010-01-13 09:57:28 UTC (rev 6654)
@@ -106,7 +106,7 @@
EnsureFactoryIsRegistered(factoryId, factoryType);
- var serviceModel =
Kernel.ComponentModelBuilder.BuildModel(serviceKey, serviceType, serviceType,
null);
+ var serviceModel =
Kernel.ComponentModelBuilder.BuildModel(serviceKey, serviceType, factoryType,
null);
cfg.Attributes["factoryId"] = factoryId;
serviceModel.Configuration = cfg;
File [modified]: FactorySupportFacility.cs
Delta lines: +1 -0
===================================================================
---
InversionOfControl/trunk/src/Castle.MicroKernel.Tests/Facilities/FactorySupport/FactorySupportFluentTestCase.cs
2010-01-13 07:01:56 UTC (rev 6653)
+++
InversionOfControl/trunk/src/Castle.MicroKernel.Tests/Facilities/FactorySupport/FactorySupportFluentTestCase.cs
2010-01-13 09:57:28 UTC (rev 6654)
@@ -83,6 +83,7 @@
Component.For<User>().Named("currentUser").Instance(user),
Component.For<AbstractCarProviderFactory>().Named("AbstractCarProviderFactory"),
Component.For<ICarProvider>()
+ .ImplementedBy<FerrariProvider>()
.Attribute("factoryId").Eq("AbstractCarProviderFactory")
.Attribute("factoryCreate").Eq("Create")
Directory:
/InversionOfControl/trunk/src/Castle.MicroKernel.Tests/Facilities/FactorySupport/
============================================================================================
File [modified]: FactorySupportFluentTestCase.cs
Delta lines: +2 -2
===================================================================
---
InversionOfControl/trunk/src/Castle.MicroKernel.Tests/Facilities/FactorySupport/FactorySupportProgrammaticTestCase.cs
2010-01-13 07:01:56 UTC (rev 6653)
+++
InversionOfControl/trunk/src/Castle.MicroKernel.Tests/Facilities/FactorySupport/FactorySupportProgrammaticTestCase.cs
2010-01-13 09:57:28 UTC (rev 6654)
@@ -15,10 +15,10 @@
namespace Castle.Facilities.FactorySupport.Tests
{
using System;
-
+ using System.Collections.Generic;
+ using Castle.Core.Configuration;
using Castle.MicroKernel;
using Castle.MicroKernel.Registration;
-
using NUnit.Framework;
File [modified]: FactorySupportProgrammaticTestCase.cs
Delta lines: +0 -90
===================================================================
---
InversionOfControl/trunk/src/Castle.MicroKernel.Tests/Facilities/FactorySupport/FactorySupportTestCase.cs
2010-01-13 07:01:56 UTC (rev 6653)
+++
InversionOfControl/trunk/src/Castle.MicroKernel.Tests/Facilities/FactorySupport/FactorySupportTestCase.cs
2010-01-13 09:57:28 UTC (rev 6654)
@@ -20,8 +20,6 @@
using Castle.Core;
using Castle.Core.Configuration;
using Castle.Facilities.FactorySupport;
- using Castle.MicroKernel.Facilities;
- using Castle.MicroKernel.Registration;
using Castle.MicroKernel.Tests.ClassComponents;
using NUnit.Framework;
@@ -75,51 +73,6 @@
Assert.IsNull(service.SomeProperty);
}
- [Test]
- public void CheckReturnValueFromTheFactory()
- {
- kernel.AddFacility("factories", new
FactorySupportFacility());
- kernel.Register(
- Component.For<PetFactory>().Parameters(
- Parameter.ForKey("petType").Eq("dog"))
- .Named("pet.factory"));
- kernel.Register(
- Component.For<Pet>().ImplementedBy<Cat>()
- .Configuration(
-
Attrib.ForName("factoryId").Eq("pet.factory"),
-
Attrib.ForName("factoryCreate").Eq("Get"))
- );
-
- Assert.Throws(typeof(FacilityException), () =>
kernel.Resolve<Pet>());
- }
-
- [Test]
- public void CheckReturnValueFromTheFactoryAccessor()
- {
- kernel.AddFacility("factories", new
FactorySupportFacility());
- kernel.Register(
- Component.For<PetFactory>()
- .Named("pet.factory"));
- kernel.Register(
- Component.For<Pet>().ImplementedBy<Cat>()
- .Configuration(
-
Attrib.ForName("instance-accessor").Eq("Dog"))
- );
- Assert.Throws(typeof(FacilityException), () =>
kernel.Resolve<Pet>());
- }
-
- [Test]
- public void Works_for_dependencies()
- {
- kernel.AddFacility("factories", new
FactorySupportFacility());
- kernel.Register(
- Component.For<Pet>().ImplementedBy<Cat>()
- .UsingFactoryMethod(() => new Cat()));
- kernel.Register(Component.For<UsesPet>());
-
- kernel.Resolve<UsesPet>();
- }
-
private ComponentModel AddComponent(string key, Type type,
string factoryMethod)
{
MutableConfiguration config = new
MutableConfiguration(key);
@@ -184,48 +137,5 @@
{
}
}
-
- public class Cat : Pet
- {
- public static Pet Dog
- {
- get { return new Dog(); }
- }
- }
- public class Dog : Pet
- {
- }
-
- public class Pet
- {
- }
-
- public class UsesPet
- {
- public Pet Pet { get; set; }
-
- public UsesPet(Pet pet)
- {
- Pet = pet;
- }
- }
-
- public class PetFactory
- {
- private readonly string type;
- public PetFactory(string petType)
- {
- type = petType;
- }
- public Pet Get()
- {
- if (type == "cat")
- return new Cat();
- else
- return new Dog();
- }
- }
-
-
}
File [modified]: FactorySupportTestCase.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.