From 4f523b19703a2f2e4c1d9c935a8a82220fcd2347 Mon Sep 17 00:00:00 2001 From: "jcwrequests@comcast.net" Date: Fri, 10 Apr 2015 21:36:42 -0400 Subject: [PATCH] Patch for Issues 832 & 833 --- .../Akka.DI.AutoFac/AutoFacDependencyResolver.cs | 5 ++--- .../WindsorDependencyResolver.cs | 6 +++--- .../Akka.DI.Core/DIActorContextAdapter.cs | 4 ++-- .../Akka.DI.Core/DIActorProducer.cs | 13 +++++++------ .../dependencyInjection/Akka.DI.Core/DIExt.cs | 4 ++-- .../Akka.DI.Core/IDependencyResolver.cs | 4 ++-- .../Akka.DI.Ninject/NinjectDependencyResolver.cs | 6 ++---- .../Akka.DI.Unity/UnityDependencyResolver.cs | 5 ++--- .../Examples/BasicAutoFacUses/Actors.cs | 2 +- .../Examples/BasicAutoFacUses/Program.cs | 5 ++++- .../Examples/BasicCastleWindsorUse/Program.cs | 4 +++- .../Examples/BasicNinjectUses/Program.cs | 3 ++- .../Examples/BasicUnityUses/Program.cs | 3 ++- 13 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/contrib/dependencyInjection/Akka.DI.AutoFac/AutoFacDependencyResolver.cs b/src/contrib/dependencyInjection/Akka.DI.AutoFac/AutoFacDependencyResolver.cs index 2cf5b53c3c0..b58dcade6fe 100644 --- a/src/contrib/dependencyInjection/Akka.DI.AutoFac/AutoFacDependencyResolver.cs +++ b/src/contrib/dependencyInjection/Akka.DI.AutoFac/AutoFacDependencyResolver.cs @@ -73,11 +73,10 @@ public Type GetType(string actorName) /// /// Name of the ActorType /// factory delegate - public Func CreateActorFactory(string actorName) + public Func CreateActorFactory(Type actorType) { return () => { - Type actorType = this.GetType(actorName); var scope = container.BeginLifetimeScope(); var actor = (ActorBase)scope.Resolve(actorType); references.Add(actor, scope); @@ -91,7 +90,7 @@ public Func CreateActorFactory(string actorName) /// Props configuration instance public Props Create() where TActor : ActorBase { - return system.GetExtension().Props(typeof(TActor).Name); + return system.GetExtension().Props(typeof(TActor)); } /// diff --git a/src/contrib/dependencyInjection/Akka.DI.CastleWindsor/WindsorDependencyResolver.cs b/src/contrib/dependencyInjection/Akka.DI.CastleWindsor/WindsorDependencyResolver.cs index f9368c40747..39a7a3ceb26 100644 --- a/src/contrib/dependencyInjection/Akka.DI.CastleWindsor/WindsorDependencyResolver.cs +++ b/src/contrib/dependencyInjection/Akka.DI.CastleWindsor/WindsorDependencyResolver.cs @@ -64,9 +64,9 @@ public Type GetType(string actorName) /// /// Name of the ActorType /// factory delegate - public Func CreateActorFactory(string actorName) + public Func CreateActorFactory(Type actorType) { - return () => (ActorBase)container.Resolve(GetType(actorName)); + return () => (ActorBase)container.Resolve(actorType); } /// /// Used Register the Configuration for the ActorType specified in TActor @@ -75,7 +75,7 @@ public Func CreateActorFactory(string actorName) /// Props configuration instance public Props Create() where TActor : ActorBase { - return system.GetExtension().Props(typeof(TActor).Name); + return system.GetExtension().Props(typeof(TActor)); } /// diff --git a/src/contrib/dependencyInjection/Akka.DI.Core/DIActorContextAdapter.cs b/src/contrib/dependencyInjection/Akka.DI.Core/DIActorContextAdapter.cs index 01e607e0a48..1fee9088eaf 100644 --- a/src/contrib/dependencyInjection/Akka.DI.Core/DIActorContextAdapter.cs +++ b/src/contrib/dependencyInjection/Akka.DI.Core/DIActorContextAdapter.cs @@ -24,9 +24,9 @@ public DIActorContextAdapter(IActorContext context) this.context = context; this.producer = context.System.GetExtension(); } - public IActorRef ActorOf(string name = null) where TActor : ActorBase, new() + public IActorRef ActorOf(string name = null) where TActor : ActorBase { - return context.ActorOf(producer.Props(typeof(TActor).Name), name); + return context.ActorOf(producer.Props(typeof(TActor)), name); } } } diff --git a/src/contrib/dependencyInjection/Akka.DI.Core/DIActorProducer.cs b/src/contrib/dependencyInjection/Akka.DI.Core/DIActorProducer.cs index 731ea42ebb1..8c5f66b93c5 100644 --- a/src/contrib/dependencyInjection/Akka.DI.Core/DIActorProducer.cs +++ b/src/contrib/dependencyInjection/Akka.DI.Core/DIActorProducer.cs @@ -16,25 +16,26 @@ namespace Akka.DI.Core public class DIActorProducer : IIndirectActorProducer { private IDependencyResolver dependencyResolver; - private string actorName; + private Type actorType; + readonly Func actorFactory; public DIActorProducer(IDependencyResolver dependencyResolver, - string actorName) + Type actorType) { if (dependencyResolver == null) throw new ArgumentNullException("dependencyResolver"); - if (actorName == null) throw new ArgumentNullException("actorName"); + if (actorType == null) throw new ArgumentNullException("actorType"); this.dependencyResolver = dependencyResolver; - this.actorName = actorName; - this.actorFactory = dependencyResolver.CreateActorFactory(actorName); + this.actorType = actorType; + this.actorFactory = dependencyResolver.CreateActorFactory(actorType); } /// /// The System.Type of the Actor specified in the constructor parameter actorName /// public Type ActorType { - get { return this.dependencyResolver.GetType(this.actorName); } + get { return this.dependencyResolver.GetType(); } } /// /// Creates an instance of the Actor based on the Type specified in the constructor parameter actorName diff --git a/src/contrib/dependencyInjection/Akka.DI.Core/DIExt.cs b/src/contrib/dependencyInjection/Akka.DI.Core/DIExt.cs index 594a73dd6e6..ad6ec48b78b 100644 --- a/src/contrib/dependencyInjection/Akka.DI.Core/DIExt.cs +++ b/src/contrib/dependencyInjection/Akka.DI.Core/DIExt.cs @@ -26,9 +26,9 @@ public void Initialize(IDependencyResolver dependencyResolver) if (dependencyResolver == null) throw new ArgumentNullException("dependencyResolver"); this.dependencyResolver = dependencyResolver; } - public Props Props(String actorName) + public Props Props(Type actorType) { - return new Props(typeof(DIActorProducer), new object[] { dependencyResolver, actorName }); + return new Props(typeof(DIActorProducer), new object[] { dependencyResolver, actorType }); } } diff --git a/src/contrib/dependencyInjection/Akka.DI.Core/IDependencyResolver.cs b/src/contrib/dependencyInjection/Akka.DI.Core/IDependencyResolver.cs index 5d59158b2c9..99c4d920801 100644 --- a/src/contrib/dependencyInjection/Akka.DI.Core/IDependencyResolver.cs +++ b/src/contrib/dependencyInjection/Akka.DI.Core/IDependencyResolver.cs @@ -21,13 +21,13 @@ public interface IDependencyResolver /// /// /// Type of the Actor specified in the actorName - Type GetType(string actorName); + Type GetType(); /// /// Creates a delegate factory based on the actorName /// /// Name of the ActorType /// factory delegate - Func CreateActorFactory(string actorName); + Func CreateActorFactory(Type actorType); /// /// Used Register the Configuration for the ActorType specified in TActor /// diff --git a/src/contrib/dependencyInjection/Akka.DI.Ninject/NinjectDependencyResolver.cs b/src/contrib/dependencyInjection/Akka.DI.Ninject/NinjectDependencyResolver.cs index 21437c64554..c754d100229 100644 --- a/src/contrib/dependencyInjection/Akka.DI.Ninject/NinjectDependencyResolver.cs +++ b/src/contrib/dependencyInjection/Akka.DI.Ninject/NinjectDependencyResolver.cs @@ -56,12 +56,10 @@ public Type GetType(string actorName) /// /// Name of the ActorType /// factory delegate - public Func CreateActorFactory(string actorName) + public Func CreateActorFactory(Type actorType) { return () => { - Type actorType = this.GetType(actorName); - return (ActorBase)container.GetService(actorType); }; } @@ -72,7 +70,7 @@ public Func CreateActorFactory(string actorName) /// Props configuration instance public Props Create() where TActor : ActorBase { - return system.GetExtension().Props(typeof(TActor).Name); + return system.GetExtension().Props(typeof(TActor)); } /// diff --git a/src/contrib/dependencyInjection/Akka.DI.Unity/UnityDependencyResolver.cs b/src/contrib/dependencyInjection/Akka.DI.Unity/UnityDependencyResolver.cs index 4561747231f..6bb871b6985 100644 --- a/src/contrib/dependencyInjection/Akka.DI.Unity/UnityDependencyResolver.cs +++ b/src/contrib/dependencyInjection/Akka.DI.Unity/UnityDependencyResolver.cs @@ -40,18 +40,17 @@ public Type GetType(string actorName) return typeCache[actorName]; } - public Func CreateActorFactory(string actorName) + public Func CreateActorFactory(Type actorType) { return () => { - var actorType = GetType(actorName); return (ActorBase)container.Resolve(actorType); }; } public Props Create() where TActor : ActorBase { - return system.GetExtension().Props(typeof(TActor).Name); + return system.GetExtension().Props(typeof(TActor)); } public void Release(ActorBase actor) diff --git a/src/contrib/dependencyInjection/Examples/BasicAutoFacUses/Actors.cs b/src/contrib/dependencyInjection/Examples/BasicAutoFacUses/Actors.cs index 01179ba39af..1c4b50d6b05 100644 --- a/src/contrib/dependencyInjection/Examples/BasicAutoFacUses/Actors.cs +++ b/src/contrib/dependencyInjection/Examples/BasicAutoFacUses/Actors.cs @@ -69,7 +69,7 @@ public void Handle(TypedActorMessage message) { Console.WriteLine("TypedParentWorker - {0} received {1}", Self.Path.Name, message); var producer = Context.System.GetExtension(); - Context.ActorOf(producer.Props("TypedWorker")).Tell(message); + Context.DI().ActorOf().Tell(message); } diff --git a/src/contrib/dependencyInjection/Examples/BasicAutoFacUses/Program.cs b/src/contrib/dependencyInjection/Examples/BasicAutoFacUses/Program.cs index 56ea77d8f7d..cc51a070b16 100644 --- a/src/contrib/dependencyInjection/Examples/BasicAutoFacUses/Program.cs +++ b/src/contrib/dependencyInjection/Examples/BasicAutoFacUses/Program.cs @@ -54,10 +54,13 @@ private static void WithHashPool() } } + Console.WriteLine("Hit Enter to close"); + Console.ReadLine(); } - Console.ReadLine(); + } + } } diff --git a/src/contrib/dependencyInjection/Examples/BasicCastleWindsorUse/Program.cs b/src/contrib/dependencyInjection/Examples/BasicCastleWindsorUse/Program.cs index 5ae92a2f6d3..ba4bb6c2edb 100644 --- a/src/contrib/dependencyInjection/Examples/BasicCastleWindsorUse/Program.cs +++ b/src/contrib/dependencyInjection/Examples/BasicCastleWindsorUse/Program.cs @@ -52,9 +52,11 @@ private static void WithHashPool() } } + Console.WriteLine("Hit Enter to exit"); + Console.ReadLine(); } - Console.ReadLine(); + } } } diff --git a/src/contrib/dependencyInjection/Examples/BasicNinjectUses/Program.cs b/src/contrib/dependencyInjection/Examples/BasicNinjectUses/Program.cs index 7c1ec70c45b..0d045e10423 100644 --- a/src/contrib/dependencyInjection/Examples/BasicNinjectUses/Program.cs +++ b/src/contrib/dependencyInjection/Examples/BasicNinjectUses/Program.cs @@ -51,10 +51,11 @@ private static void WithHashPool() } } + Console.WriteLine("Hit Enter to exit"); + Console.ReadLine(); } - Console.ReadLine(); } } } diff --git a/src/contrib/dependencyInjection/Examples/BasicUnityUses/Program.cs b/src/contrib/dependencyInjection/Examples/BasicUnityUses/Program.cs index a54124e8151..25d60b82063 100644 --- a/src/contrib/dependencyInjection/Examples/BasicUnityUses/Program.cs +++ b/src/contrib/dependencyInjection/Examples/BasicUnityUses/Program.cs @@ -55,10 +55,11 @@ private static void WithHashPool() } } + Console.WriteLine("Hit Enter to exit"); + Console.ReadLine(); } - Console.ReadLine(); } } }