{"action":"closed","issue":{"url":"https://api.github.com/repos/akkadotnet/akka.net/issues/1281","labels_url":"https://api.github.com/repos/akkadotnet/akka.net/issues/1281/labels{/name}","comments_url":"https://api.github.com/repos/akkadotnet/akka.net/issues/1281/comments","events_url":"https://api.github.com/repos/akkadotnet/akka.net/issues/1281/events","html_url":"https://github.com/akkadotnet/akka.net/issues/1281","id":103980728,"number":1281,"title":"DI - How to inject two actors thru DI? ","user":{"login":"michaelsync","id":192911,"avatar_url":"https://avatars.githubusercontent.com/u/192911?v=3","gravatar_id":"","url":"https://api.github.com/users/michaelsync","html_url":"https://github.com/michaelsync","followers_url":"https://api.github.com/users/michaelsync/followers","following_url":"https://api.github.com/users/michaelsync/following{/other_user}","gists_url":"https://api.github.com/users/michaelsync/gists{/gist_id}","starred_url":"https://api.github.com/users/michaelsync/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaelsync/subscriptions","organizations_url":"https://api.github.com/users/michaelsync/orgs","repos_url":"https://api.github.com/users/michaelsync/repos","events_url":"https://api.github.com/users/michaelsync/events{/privacy}","received_events_url":"https://api.github.com/users/michaelsync/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-31T03:57:17Z","updated_at":"2015-11-12T21:13:52Z","closed_at":"2015-11-12T21:13:52Z","body":"What I am trying to do is to pass the two actors (mummy actor and daddy actor) to kid actor. As it's the best practice to use the actor reference instead of actor, I used IActorRef for both mummy actor and daddy actor to be injected thru DI with named parameter. But I am getting \"mummyActor is not unique\" error. Any idea how to solve it? \r\n\r\n```cs\r\n\tusing System;\r\n\tusing System.Threading.Tasks;\r\n\tusing Akka.Actor;\r\n\tusing Akka.DI.AutoFac;\r\n\tusing Akka.DI.Core;\r\n\tusing Autofac;\r\n\tusing Autofac.Core;\r\n\r\n\r\n\tnamespace Akka.DI.AutoFac.ExampleConsole {\r\n\t\t\r\n\t\tpublic class DaddyActor : ReceiveActor {\r\n\t\t\tpublic DaddyActor() {\r\n\t\t\t\tReceive<DoneEatingMessage>(m => {\r\n\t\t\t\t\tConsole.WriteLine(\"Kid finished eating. So what? ~ Dad\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t}\r\n\r\n\r\n\t\tpublic class MummyActor : ReceiveActor {\r\n\t\t\tpublic MummyActor() {\r\n\t\t\t\tReceive<DoneEatingMessage>(m => {\r\n\t\t\t\t\tConsole.WriteLine(\"Kid finished eating. Time to clean up! ~Mummy\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic class KidActor : ReceiveActor {\r\n\r\n\t\t\tprivate IService _service;\r\n\r\n\t\t\tprivate IActorRef _mummyActor;\r\n\t\t\tprivate IActorRef _daddyActor;\r\n\r\n\t\t\tpublic KidActor(IService service, IActorRef mummyActor, IActorRef daddyActor) {\r\n\t\t\t\tthis._service = service;\r\n\t\t\t\tthis._mummyActor = mummyActor;\r\n\t\t\t\tthis._daddyActor = daddyActor;\r\n\r\n\t\t\t\tReceive<EatMessage>(m=>{\r\n\t\t\t\t\tvar food = service.GetFood();\r\n\t\t\t\t\tConsole.WriteLine(\"Kid eat this food {0}\", food);\r\n\t\t\t\t\t_mummyActor.Tell(new DoneEatingMessage());\r\n\t\t\t\t});\r\n\t\t\t}\r\n\r\n\t\t\t\r\n\t\t}\r\n\r\n\t\tpublic class EatMessage{    }\r\n\t\tpublic class DoneEatingMessage { }\r\n\r\n\t\tpublic interface IService {\r\n\t\t\tstring GetFood();\r\n\t\t}\r\n\t\tpublic class FoodService : IService {\r\n\r\n\t\t\tpublic string GetFood() {\r\n\t\t\t\treturn \"banana\";\r\n\t\t\t}\r\n\t\t}\r\n\t\tclass Program {\r\n\t\t\tstatic ActorSystem _actorSystem;\r\n\t\t\tstatic void Main(string[] args) {\r\n\t\t\t\t\r\n\t\t\t\tvar builder = new Autofac.ContainerBuilder();\r\n\t\t\t\tbuilder.RegisterType<FoodService>().As<IService>();\r\n\t\t\t\tbuilder.RegisterType<MummyActor>().InstancePerDependency();\r\n\t\t\t\tbuilder.RegisterType<DaddyActor>().InstancePerDependency();\r\n\r\n\t\t\t\tbuilder.Register(c => _actorSystem.ActorOf(_actorSystem.DI().Props<DaddyActor>(), \"daddyActor\"))\r\n\t\t\t\t\t.Named<IActorRef>(\"daddyActorRef\")\r\n\t\t\t\t\t.AsSelf();\r\n\r\n\t\t\t\tbuilder.Register(c => _actorSystem.ActorOf(_actorSystem.DI().Props<MummyActor>(), \"mummyActor\"))\r\n\t\t\t\t\t.Named<IActorRef>(\"mummyActorRef\")\r\n\t\t\t\t\t.AsSelf();\r\n\r\n\t\t\t\t\r\n\t\t\t\t\r\n\t\t\t\tbuilder.RegisterType<KidActor>()\r\n\t\t\t\t\t.WithParameter(\r\n\t\t\t\t\t  new ResolvedParameter(\r\n\t\t\t\t\t\t   (pi, ctx) => pi.ParameterType == typeof(MummyActor),\r\n\t\t\t\t\t\t   (pi, ctx) => ctx.ResolveNamed<IActorRef>(\"mummyActorRef\")\r\n\t\t\t\t\t\t)\r\n\t\t\t\t\t)\r\n\t\t\t\t\t.WithParameter(\r\n\t\t\t\t\t  new ResolvedParameter(\r\n\t\t\t\t\t\t   (pi, ctx) => pi.ParameterType == typeof(DaddyActor),\r\n\t\t\t\t\t\t   (pi, ctx) => ctx.ResolveNamed<IActorRef>(\"daddyActorRef\")\r\n\t\t\t\t\t\t)\r\n\t\t\t\t\t)\r\n\t\t\t\t\t.InstancePerDependency();\r\n\r\n\t\t\t\tvar container = builder.Build();\r\n\r\n\t\t\t\t_actorSystem = ActorSystem.Create(\"ActorDISystem\");\r\n\t\t\t\tvar propsResolver = new AutoFacDependencyResolver(container, _actorSystem);\r\n\r\n\t\t\t\t\r\n\t\t\t\tvar kidActorProps = _actorSystem.DI().Props<KidActor>();\r\n\t\t\t\tvar kidActor = _actorSystem.ActorOf(kidActorProps, \"kidActor\");\r\n\r\n\t\t\t\tkidActor.Tell(new EatMessage());\r\n\r\n\t\t\t\tConsole.WriteLine(\"Holah\");\r\n\t\t\t\tConsole.ReadLine();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n```"}}