{"action":"created","issue":{"url":"https://api.github.com/repos/akkadotnet/akka.net/issues/2334","repository_url":"https://api.github.com/repos/akkadotnet/akka.net","labels_url":"https://api.github.com/repos/akkadotnet/akka.net/issues/2334/labels{/name}","comments_url":"https://api.github.com/repos/akkadotnet/akka.net/issues/2334/comments","events_url":"https://api.github.com/repos/akkadotnet/akka.net/issues/2334/events","html_url":"https://github.com/akkadotnet/akka.net/issues/2334","id":181240472,"number":2334,"title":"Akka.Net should allow for \"Strongly typed\" actors and actor references","user":{"login":"neils-s","id":5400894,"avatar_url":"https://avatars.githubusercontent.com/u/5400894?v=3","gravatar_id":"","url":"https://api.github.com/users/neils-s","html_url":"https://github.com/neils-s","followers_url":"https://api.github.com/users/neils-s/followers","following_url":"https://api.github.com/users/neils-s/following{/other_user}","gists_url":"https://api.github.com/users/neils-s/gists{/gist_id}","starred_url":"https://api.github.com/users/neils-s/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neils-s/subscriptions","organizations_url":"https://api.github.com/users/neils-s/orgs","repos_url":"https://api.github.com/users/neils-s/repos","events_url":"https://api.github.com/users/neils-s/events{/privacy}","received_events_url":"https://api.github.com/users/neils-s/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/akkadotnet/akka.net/labels/akka-actor","name":"akka-actor","color":"c7def8"},{"url":"https://api.github.com/repos/akkadotnet/akka.net/labels/discussion","name":"discussion","color":"0052cc"},{"url":"https://api.github.com/repos/akkadotnet/akka.net/labels/enhancement","name":"enhancement","color":"207de5"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-10-05T19:12:07Z","updated_at":"2016-10-07T20:31:41Z","closed_at":null,"body":"When I define an ```IActorRef``` in code, I have no way to constrain the type of actor that will be referenced by that variable.  This is bad because it allows me to screw up my code by building a method that expects one type of ```IActorRef```, but receives another.\r\n\r\nAs an example, say I have the following code:\r\n```\r\nusing Akka.Actor;\r\n\r\nnamespace Test_of_Akka_functionality\r\n{\r\n    class Driver\r\n    {\r\n        public class GoodActor:ReceiveActor\r\n        {\r\n            public GoodActor()\r\n            {\r\n                Receive<goodMessage>(\r\n                    m => onGoodMessage((goodMessage)m)\r\n                    );\r\n            }\r\n            public class goodMessage { }\r\n            private void onGoodMessage(goodMessage message) { }\r\n        }\r\n        public class BadActor : ReceiveActor\r\n        {\r\n            public BadActor()\r\n            {\r\n                Receive<badMessage>(\r\n                    m => onBadMessage((badMessage)m)\r\n                    );\r\n            }\r\n            public class badMessage { }\r\n            private void onBadMessage(badMessage message) { }\r\n        }\r\n\r\n        public static void Main(string[] args)\r\n        {\r\n            ActorSystem MyActorSystem = ActorSystem.Create(\"MyActorSystem\");\r\n            IActorRef aGoodActor = MyActorSystem.ActorOf(Props.Create<GoodActor>(\"a_good_little_actor\"));\r\n            IActorRef aBadActor = MyActorSystem.ActorOf(Props.Create<BadActor>(\"bad_actor_no_candy\"));\r\n\r\n            sendGoodMessage(aBadActor);\r\n        }\r\n\r\n        public static void sendGoodMessage(IActorRef whichActor)\r\n        {\r\n            whichActor.Tell(new GoodActor.goodMessage());\r\n        }\r\n    }\r\n}\r\n```\r\nThis code gives no compiler errors, even though I've built bad code that sends a good message to a bad actor.  Ideally, I could specify that ```sendGoodMessage()``` takes in an instance of ```IActorRef``` that refers to a *specific* kind of actor.\r\nFor example, if Akka.Net allowed generic types like ```IActorRef<GoodActor>``` and ```IActorRef<BadActor>```, then I could specify the function signature of sendGoodMessage as:\r\n```\r\n        public static void sendGoodMessage(IActorRef<GoodActor> whichActor)\r\n        {\r\n            whichActor.Tell(new GoodActor.goodMessage());\r\n        }\r\n```\r\nThis would make it harder for me to shoot myself in the foot.\r\n\r\nThere are a couple of similar complaints on Stackoverflow.com that reference GitHub repositories where people are trying to work around this deficit.  For additional details see the following:\r\n[http://stackoverflow.com/questions/37607785/how-to-ensure-at-compile-time-that-messages-are-send-to-the-right-actor-in-akka](url)\r\n[http://stackoverflow.com/questions/37734390/strong-typing-for-iactorref-for-dependencies)](url)\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/akkadotnet/akka.net/issues/comments/252353931","html_url":"https://github.com/akkadotnet/akka.net/issues/2334#issuecomment-252353931","issue_url":"https://api.github.com/repos/akkadotnet/akka.net/issues/2334","id":252353931,"user":{"login":"MrTortoise","id":3891944,"avatar_url":"https://avatars.githubusercontent.com/u/3891944?v=3","gravatar_id":"","url":"https://api.github.com/users/MrTortoise","html_url":"https://github.com/MrTortoise","followers_url":"https://api.github.com/users/MrTortoise/followers","following_url":"https://api.github.com/users/MrTortoise/following{/other_user}","gists_url":"https://api.github.com/users/MrTortoise/gists{/gist_id}","starred_url":"https://api.github.com/users/MrTortoise/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MrTortoise/subscriptions","organizations_url":"https://api.github.com/users/MrTortoise/orgs","repos_url":"https://api.github.com/users/MrTortoise/repos","events_url":"https://api.github.com/users/MrTortoise/events{/privacy}","received_events_url":"https://api.github.com/users/MrTortoise/received_events","type":"User","site_admin":false},"created_at":"2016-10-07T20:31:40Z","updated_at":"2016-10-07T20:31:40Z","body":"I thought not having this was a conscious design decision!"}}
{"actor":{"display_login":"MrTortoise"}}