Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch for Issues 832 & 833 #835

Merged
merged 1 commit into from
Apr 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ public Type GetType(string actorName)
/// </summary>
/// <param name="actorName">Name of the ActorType</param>
/// <returns>factory delegate</returns>
public Func<ActorBase> CreateActorFactory(string actorName)
public Func<ActorBase> CreateActorFactory(Type actorType)
{
return () =>
{
Type actorType = this.GetType(actorName);
var scope = container.BeginLifetimeScope();
var actor = (ActorBase)scope.Resolve(actorType);
references.Add(actor, scope);
Expand All @@ -91,7 +90,7 @@ public Func<ActorBase> CreateActorFactory(string actorName)
/// <returns>Props configuration instance</returns>
public Props Create<TActor>() where TActor : ActorBase
{
return system.GetExtension<DIExt>().Props(typeof(TActor).Name);
return system.GetExtension<DIExt>().Props(typeof(TActor));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public Type GetType(string actorName)
/// </summary>
/// <param name="actorName">Name of the ActorType</param>
/// <returns>factory delegate</returns>
public Func<ActorBase> CreateActorFactory(string actorName)
public Func<ActorBase> CreateActorFactory(Type actorType)
{
return () => (ActorBase)container.Resolve(GetType(actorName));
return () => (ActorBase)container.Resolve(actorType);
}
/// <summary>
/// Used Register the Configuration for the ActorType specified in TActor
Expand All @@ -75,7 +75,7 @@ public Func<ActorBase> CreateActorFactory(string actorName)
/// <returns>Props configuration instance</returns>
public Props Create<TActor>() where TActor : ActorBase
{
return system.GetExtension<DIExt>().Props(typeof(TActor).Name);
return system.GetExtension<DIExt>().Props(typeof(TActor));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public DIActorContextAdapter(IActorContext context)
this.context = context;
this.producer = context.System.GetExtension<DIExt>();
}
public IActorRef ActorOf<TActor>(string name = null) where TActor : ActorBase, new()
public IActorRef ActorOf<TActor>(string name = null) where TActor : ActorBase
{
return context.ActorOf(producer.Props(typeof(TActor).Name), name);
return context.ActorOf(producer.Props(typeof(TActor)), name);
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/contrib/dependencyInjection/Akka.DI.Core/DIActorProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,26 @@ namespace Akka.DI.Core
public class DIActorProducer : IIndirectActorProducer
{
private IDependencyResolver dependencyResolver;
private string actorName;
private Type actorType;

readonly Func<ActorBase> 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);
}
/// <summary>
/// The System.Type of the Actor specified in the constructor parameter actorName
/// </summary>
public Type ActorType
{
get { return this.dependencyResolver.GetType(this.actorName); }
get { return this.dependencyResolver.GetType(); }
}
/// <summary>
/// Creates an instance of the Actor based on the Type specified in the constructor parameter actorName
Expand Down
4 changes: 2 additions & 2 deletions src/contrib/dependencyInjection/Akka.DI.Core/DIExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public interface IDependencyResolver
/// </summary>
/// <param name="actorName"></param>
/// <returns>Type of the Actor specified in the actorName</returns>
Type GetType(string actorName);
Type GetType();
/// <summary>
/// Creates a delegate factory based on the actorName
/// </summary>
/// <param name="actorName">Name of the ActorType</param>
/// <returns>factory delegate</returns>
Func<ActorBase> CreateActorFactory(string actorName);
Func<ActorBase> CreateActorFactory(Type actorType);
/// <summary>
/// Used Register the Configuration for the ActorType specified in TActor
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ public Type GetType(string actorName)
/// </summary>
/// <param name="actorName">Name of the ActorType</param>
/// <returns>factory delegate</returns>
public Func<ActorBase> CreateActorFactory(string actorName)
public Func<ActorBase> CreateActorFactory(Type actorType)
{
return () =>
{
Type actorType = this.GetType(actorName);

return (ActorBase)container.GetService(actorType);
};
}
Expand All @@ -72,7 +70,7 @@ public Func<ActorBase> CreateActorFactory(string actorName)
/// <returns>Props configuration instance</returns>
public Props Create<TActor>() where TActor : ActorBase
{
return system.GetExtension<DIExt>().Props(typeof(TActor).Name);
return system.GetExtension<DIExt>().Props(typeof(TActor));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,17 @@ public Type GetType(string actorName)
return typeCache[actorName];
}

public Func<ActorBase> CreateActorFactory(string actorName)
public Func<ActorBase> CreateActorFactory(Type actorType)
{
return () =>
{
var actorType = GetType(actorName);
return (ActorBase)container.Resolve(actorType);
};
}

public Props Create<TActor>() where TActor : ActorBase
{
return system.GetExtension<DIExt>().Props(typeof(TActor).Name);
return system.GetExtension<DIExt>().Props(typeof(TActor));
}

public void Release(ActorBase actor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void Handle(TypedActorMessage message)
{
Console.WriteLine("TypedParentWorker - {0} received {1}", Self.Path.Name, message);
var producer = Context.System.GetExtension<DIExt>();
Context.ActorOf(producer.Props("TypedWorker")).Tell(message);
Context.DI().ActorOf<TypedActor>().Tell(message);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ private static void WithHashPool()

}
}
Console.WriteLine("Hit Enter to close");
Console.ReadLine();
}

Console.ReadLine();

}

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ private static void WithHashPool()

}
}
Console.WriteLine("Hit Enter to exit");
Console.ReadLine();
}

Console.ReadLine();

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ private static void WithHashPool()

}
}
Console.WriteLine("Hit Enter to exit");
Console.ReadLine();
}


Console.ReadLine();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ private static void WithHashPool()

}
}
Console.WriteLine("Hit Enter to exit");
Console.ReadLine();
}


Console.ReadLine();
}
}
}
Expand Down