{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/orleans/pulls/comments/37265888","id":37265888,"diff_hunk":"@@ -294,6 +314,49 @@ internal Silo(string name, SiloType siloType, ClusterConfiguration config, ILoca\n             logger.Info(ErrorCode.SiloInitializingFinished, \"-------------- Started silo {0}, ConsistentHashCode {1:X} --------------\", SiloAddress.ToLongString(), SiloAddress.GetConsistentHashCode());\n         }\n \n+        private void InitializeDependencyResolver()\n+        {\n+            if (String.IsNullOrWhiteSpace(nodeConfig.DependencyResolverProviderName))\n+            {\n+                return;\n+            }\n+\n+            //\n+            // Load the assemblies from the Silo's directory, since the dependency resolver's type is not directly referenced,\n+            // so the ProviderLoader will not find it within the loaded assemblies.\n+            //\n+\n+            var siloRoot = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);\n+\n+            var directories = new Dictionary<string, SearchOption>\n+            {\n+                {siloRoot, SearchOption.TopDirectoryOnly}\n+            };\n+\n+            AssemblyLoaderReflectionCriterion[] loadCriteria =\n+            {\n+                AssemblyLoaderCriteria.LoadTypesAssignableFrom(\n+                    typeof (IDependencyResolverProvider))\n+            };\n+\n+            var discoveredAssemblyLocations = AssemblyLoader.LoadAssemblies(directories, null, loadCriteria, logger);\n+\n+            var dependencyResolverProviderManager = new DependencyResolverProviderManager(ProviderCategoryConfiguration.DEPDENDENCY_RESOLVER_PROVIDER_CATEGORY_NAME);","path":"src/OrleansRuntime/Silo/Silo.cs","position":159,"original_position":159,"commit_id":"d2b2adc099110092e54ec12cfbc68adafec83fa0","original_commit_id":"d2b2adc099110092e54ec12cfbc68adafec83fa0","user":{"login":"gabikliot","id":10171207,"avatar_url":"https://avatars.githubusercontent.com/u/10171207?v=3","gravatar_id":"","url":"https://api.github.com/users/gabikliot","html_url":"https://github.com/gabikliot","followers_url":"https://api.github.com/users/gabikliot/followers","following_url":"https://api.github.com/users/gabikliot/following{/other_user}","gists_url":"https://api.github.com/users/gabikliot/gists{/gist_id}","starred_url":"https://api.github.com/users/gabikliot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gabikliot/subscriptions","organizations_url":"https://api.github.com/users/gabikliot/orgs","repos_url":"https://api.github.com/users/gabikliot/repos","events_url":"https://api.github.com/users/gabikliot/events{/privacy}","received_events_url":"https://api.github.com/users/gabikliot/received_events","type":"User","site_admin":false},"body":"can all the code in this method go into `DependencyResolverProviderManager`, so here we will only instantiate `DependencyResolverProviderManager`, call Load on it and then call `GetDependencyResolver` or something? I just don't want to pollute the silo code with all those details about `AssemblyLoaderReflectionCriterion` and etc...","created_at":"2015-08-18T05:44:34Z","updated_at":"2015-08-18T05:44:34Z","html_url":"https://github.com/dotnet/orleans/pull/709#discussion_r37265888","pull_request_url":"https://api.github.com/repos/dotnet/orleans/pulls/709","_links":{"self":{"href":"https://api.github.com/repos/dotnet/orleans/pulls/comments/37265888"},"html":{"href":"https://github.com/dotnet/orleans/pull/709#discussion_r37265888"},"pull_request":{"href":"https://api.github.com/repos/dotnet/orleans/pulls/709"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/orleans/pulls/709","id":42649741,"html_url":"https://github.com/dotnet/orleans/pull/709","diff_url":"https://github.com/dotnet/orleans/pull/709.diff","patch_url":"https://github.com/dotnet/orleans/pull/709.patch","issue_url":"https://api.github.com/repos/dotnet/orleans/issues/709","number":709,"state":"open","locked":false,"title":"Added DI functionality.","user":{"login":"attilah","id":230432,"avatar_url":"https://avatars.githubusercontent.com/u/230432?v=3","gravatar_id":"","url":"https://api.github.com/users/attilah","html_url":"https://github.com/attilah","followers_url":"https://api.github.com/users/attilah/followers","following_url":"https://api.github.com/users/attilah/following{/other_user}","gists_url":"https://api.github.com/users/attilah/gists{/gist_id}","starred_url":"https://api.github.com/users/attilah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/attilah/subscriptions","organizations_url":"https://api.github.com/users/attilah/orgs","repos_url":"https://api.github.com/users/attilah/repos","events_url":"https://api.github.com/users/attilah/events{/privacy}","received_events_url":"https://api.github.com/users/attilah/received_events","type":"User","site_admin":false},"body":"### Modifications:\r\n\r\n1) Added interface definition for IDependencyResolver and IDependencyScope (not yet used). These interfaces are copied over from WebApi (https://aspnetwebstack.codeplex.com/SourceControl/latest#src/System.Web.Http/Dependencies/IDependencyResolver.cs)\r\n2) Added IDependencyResolverProvider interface to support the new provider type.\r\n3) Configuraton now can contain a DependencyResolverProviders section for the new provider.\r\n4) Default (node level) configuration now supports a DependencyResolver element which currently has only a ProviderName attribute. It must match a provider name in the DependencyResolverProviders section. It is available in NodeConfiguration class DependencyResolverProviderName property.\r\n5) Added DependencyResolverProviderManager class which is responsible for loading the provider from config and return a provider based on its name.\r\n6) Added DefaultResolver implementation which is just an interface compliant Activator.CreateInstance wrapper. It is the original behavior of Orleans. If no DI is configured then it is used by default.\r\n7) Catalog.CreateGrainInstance method changed to utilize the currently set Silo level IDependencyResolver instance for grain creation and retrieval.\r\n\r\n### Orleans.Autofac project:\r\nAutofac DI implementation for Orleans. The code is taken from Autofac.WebApi project (https://github.com/autofac/Autofac.WebApi/blob/master/src/Autofac.Integration.WebApi/AutofacWebApiDependencyResolver.cs).\r\n\r\n### Test:\r\nModified SimpleGrainTest to leverage the new DI functionality: DependencyResolverGrainTests class.\r\n\r\nAutofacDepdendencyResolverProvider class: this needed to be implement per project to init and configure a IoC container and return a IDependencyResolver instance.\r\nOrleansDependencyResolverConfigurationForTesting.xml: this file has the DI configuration for the test.\r\n\r\n### Known issue:\r\n\r\nNeed to find THE proper place for the TestingSiloHost to dispose the DependencyResolver within the created Silo instances, maybe Silo needs to be IDisposable to handle it itself.\r\nPossible enhancements:\r\n\r\nImplement (copy ;-)) other DI container implementations for Orleans. The existing ones supporting WebApi are supporting Orleans too.\r\nImplement other dependency scopes: per grain, per activation, per grain type, per message.\r\nMove more and more Orleans infrastructure code to be DI based: ProviderManagers, Providers, Logging, etc...","created_at":"2015-08-18T00:26:14Z","updated_at":"2015-08-18T05:44:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a69db34a3805226017ef3b4012654be881ca0a3b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/orleans/pulls/709/commits","review_comments_url":"https://api.github.com/repos/dotnet/orleans/pulls/709/comments","review_comment_url":"https://api.github.com/repos/dotnet/orleans/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/orleans/issues/709/comments","statuses_url":"https://api.github.com/repos/dotnet/orleans/statuses/d2b2adc099110092e54ec12cfbc68adafec83fa0","head":{"label":"attilah:master","ref":"master","sha":"d2b2adc099110092e54ec12cfbc68adafec83fa0","user":{"login":"attilah","id":230432,"avatar_url":"https://avatars.githubusercontent.com/u/230432?v=3","gravatar_id":"","url":"https://api.github.com/users/attilah","html_url":"https://github.com/attilah","followers_url":"https://api.github.com/users/attilah/followers","following_url":"https://api.github.com/users/attilah/following{/other_user}","gists_url":"https://api.github.com/users/attilah/gists{/gist_id}","starred_url":"https://api.github.com/users/attilah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/attilah/subscriptions","organizations_url":"https://api.github.com/users/attilah/orgs","repos_url":"https://api.github.com/users/attilah/repos","events_url":"https://api.github.com/users/attilah/events{/privacy}","received_events_url":"https://api.github.com/users/attilah/received_events","type":"User","site_admin":false},"repo":{"id":40939260,"name":"orleans","full_name":"attilah/orleans","owner":{"login":"attilah","id":230432,"avatar_url":"https://avatars.githubusercontent.com/u/230432?v=3","gravatar_id":"","url":"https://api.github.com/users/attilah","html_url":"https://github.com/attilah","followers_url":"https://api.github.com/users/attilah/followers","following_url":"https://api.github.com/users/attilah/following{/other_user}","gists_url":"https://api.github.com/users/attilah/gists{/gist_id}","starred_url":"https://api.github.com/users/attilah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/attilah/subscriptions","organizations_url":"https://api.github.com/users/attilah/orgs","repos_url":"https://api.github.com/users/attilah/repos","events_url":"https://api.github.com/users/attilah/events{/privacy}","received_events_url":"https://api.github.com/users/attilah/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/attilah/orleans","description":"Orleans - Distributed Virtual Actor Model","fork":true,"url":"https://api.github.com/repos/attilah/orleans","forks_url":"https://api.github.com/repos/attilah/orleans/forks","keys_url":"https://api.github.com/repos/attilah/orleans/keys{/key_id}","collaborators_url":"https://api.github.com/repos/attilah/orleans/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/attilah/orleans/teams","hooks_url":"https://api.github.com/repos/attilah/orleans/hooks","issue_events_url":"https://api.github.com/repos/attilah/orleans/issues/events{/number}","events_url":"https://api.github.com/repos/attilah/orleans/events","assignees_url":"https://api.github.com/repos/attilah/orleans/assignees{/user}","branches_url":"https://api.github.com/repos/attilah/orleans/branches{/branch}","tags_url":"https://api.github.com/repos/attilah/orleans/tags","blobs_url":"https://api.github.com/repos/attilah/orleans/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/attilah/orleans/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/attilah/orleans/git/refs{/sha}","trees_url":"https://api.github.com/repos/attilah/orleans/git/trees{/sha}","statuses_url":"https://api.github.com/repos/attilah/orleans/statuses/{sha}","languages_url":"https://api.github.com/repos/attilah/orleans/languages","stargazers_url":"https://api.github.com/repos/attilah/orleans/stargazers","contributors_url":"https://api.github.com/repos/attilah/orleans/contributors","subscribers_url":"https://api.github.com/repos/attilah/orleans/subscribers","subscription_url":"https://api.github.com/repos/attilah/orleans/subscription","commits_url":"https://api.github.com/repos/attilah/orleans/commits{/sha}","git_commits_url":"https://api.github.com/repos/attilah/orleans/git/commits{/sha}","comments_url":"https://api.github.com/repos/attilah/orleans/comments{/number}","issue_comment_url":"https://api.github.com/repos/attilah/orleans/issues/comments{/number}","contents_url":"https://api.github.com/repos/attilah/orleans/contents/{+path}","compare_url":"https://api.github.com/repos/attilah/orleans/compare/{base}...{head}","merges_url":"https://api.github.com/repos/attilah/orleans/merges","archive_url":"https://api.github.com/repos/attilah/orleans/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/attilah/orleans/downloads","issues_url":"https://api.github.com/repos/attilah/orleans/issues{/number}","pulls_url":"https://api.github.com/repos/attilah/orleans/pulls{/number}","milestones_url":"https://api.github.com/repos/attilah/orleans/milestones{/number}","notifications_url":"https://api.github.com/repos/attilah/orleans/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/attilah/orleans/labels{/name}","releases_url":"https://api.github.com/repos/attilah/orleans/releases{/id}","created_at":"2015-08-18T00:15:10Z","updated_at":"2015-08-18T00:15:13Z","pushed_at":"2015-08-18T00:24:56Z","git_url":"git://github.com/attilah/orleans.git","ssh_url":"git@github.com:attilah/orleans.git","clone_url":"https://github.com/attilah/orleans.git","svn_url":"https://github.com/attilah/orleans","homepage":"http://dotnet.github.io/orleans","size":31402,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dotnet:master","ref":"master","sha":"30a29aa0bae9b7d34da04fe3738478eef5a02076","user":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":28232663,"name":"orleans","full_name":"dotnet/orleans","owner":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dotnet/orleans","description":"Orleans - Distributed Virtual Actor Model","fork":false,"url":"https://api.github.com/repos/dotnet/orleans","forks_url":"https://api.github.com/repos/dotnet/orleans/forks","keys_url":"https://api.github.com/repos/dotnet/orleans/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/orleans/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/orleans/teams","hooks_url":"https://api.github.com/repos/dotnet/orleans/hooks","issue_events_url":"https://api.github.com/repos/dotnet/orleans/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/orleans/events","assignees_url":"https://api.github.com/repos/dotnet/orleans/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/orleans/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/orleans/tags","blobs_url":"https://api.github.com/repos/dotnet/orleans/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/orleans/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/orleans/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/orleans/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/orleans/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/orleans/languages","stargazers_url":"https://api.github.com/repos/dotnet/orleans/stargazers","contributors_url":"https://api.github.com/repos/dotnet/orleans/contributors","subscribers_url":"https://api.github.com/repos/dotnet/orleans/subscribers","subscription_url":"https://api.github.com/repos/dotnet/orleans/subscription","commits_url":"https://api.github.com/repos/dotnet/orleans/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/orleans/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/orleans/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/orleans/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/orleans/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/orleans/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/orleans/merges","archive_url":"https://api.github.com/repos/dotnet/orleans/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/orleans/downloads","issues_url":"https://api.github.com/repos/dotnet/orleans/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/orleans/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/orleans/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/orleans/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/orleans/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/orleans/releases{/id}","created_at":"2014-12-19T14:32:50Z","updated_at":"2015-08-17T18:30:15Z","pushed_at":"2015-08-18T00:26:14Z","git_url":"git://github.com/dotnet/orleans.git","ssh_url":"git@github.com:dotnet/orleans.git","clone_url":"https://github.com/dotnet/orleans.git","svn_url":"https://github.com/dotnet/orleans","homepage":"http://dotnet.github.io/orleans","size":31402,"stargazers_count":1094,"watchers_count":1094,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":241,"mirror_url":null,"open_issues_count":81,"forks":241,"open_issues":81,"watchers":1094,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/orleans/pulls/709"},"html":{"href":"https://github.com/dotnet/orleans/pull/709"},"issue":{"href":"https://api.github.com/repos/dotnet/orleans/issues/709"},"comments":{"href":"https://api.github.com/repos/dotnet/orleans/issues/709/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/orleans/pulls/709/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/orleans/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/orleans/pulls/709/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/orleans/statuses/d2b2adc099110092e54ec12cfbc68adafec83fa0"}}}}