{"action":"created","issue":{"url":"https://api.github.com/repos/MvvmCross/MvvmCross-Plugins/issues/137","repository_url":"https://api.github.com/repos/MvvmCross/MvvmCross-Plugins","labels_url":"https://api.github.com/repos/MvvmCross/MvvmCross-Plugins/issues/137/labels{/name}","comments_url":"https://api.github.com/repos/MvvmCross/MvvmCross-Plugins/issues/137/comments","events_url":"https://api.github.com/repos/MvvmCross/MvvmCross-Plugins/issues/137/events","html_url":"https://github.com/MvvmCross/MvvmCross-Plugins/issues/137","id":178122580,"number":137,"title":"JsonLocalization: MvxTextProviderBuilder virtual call in constructor","user":{"login":"LeRondPoint","id":15251145,"avatar_url":"https://avatars.githubusercontent.com/u/15251145?v=3","gravatar_id":"","url":"https://api.github.com/users/LeRondPoint","html_url":"https://github.com/LeRondPoint","followers_url":"https://api.github.com/users/LeRondPoint/followers","following_url":"https://api.github.com/users/LeRondPoint/following{/other_user}","gists_url":"https://api.github.com/users/LeRondPoint/gists{/gist_id}","starred_url":"https://api.github.com/users/LeRondPoint/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LeRondPoint/subscriptions","organizations_url":"https://api.github.com/users/LeRondPoint/orgs","repos_url":"https://api.github.com/users/LeRondPoint/repos","events_url":"https://api.github.com/users/LeRondPoint/events{/privacy}","received_events_url":"https://api.github.com/users/LeRondPoint/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-20T17:23:01Z","updated_at":"2016-09-20T17:25:15Z","closed_at":null,"body":"In it's constructor, MvxTextProviderBuilder calls its LoadResources method which refers to the virtual property ResourceFiles.  This is an issue as we might access stuff that isn't completely initialized yet, as we well know.\r\n\r\nMy specific use-case is that I'm passing my default text type key as a parameter to my text provider class.  I also use reflection to find all ViewModels and create the mappings for those classes.  Of course, my default type key is null when trying to setup the dictionary.  Ideally, the initial loading of text resources would be deferred.\r\n\r\n```\r\n        public TextProviderBuilder(string textFolder, string defaultTypeKey)\r\n            : base(Mvx.Resolve<ResourceLocator>().ResourcesNamespace, textFolder, new MvxEmbeddedJsonDictionaryTextProvider(false))\r\n        {\r\n            _DefaultTypeKey = defaultTypeKey;\r\n        }\r\n\r\n        protected override IDictionary<string, string> ResourceFiles\r\n        {\r\n            get\r\n            {\r\n                Dictionary<string, string> dictionary = new Dictionary<string, string>();\r\n                IEnumerable<TypeInfo> localizedViewModelTypes = Mvx.Resolve<ResourceLocator>()\r\n                                                                   .ResourcesAssembly.DefinedTypes.Where(\r\n                                                                       t => t.IsSubclassOf(typeof(MvxLocalizedViewModel)));\r\n\r\n                dictionary.Add(_DefaultTypeKey, _DefaultTypeKey);\r\n\r\n                foreach(TypeInfo type in localizedViewModelTypes)\r\n                {\r\n                    string typeKey = type.FullName;\r\n\r\n                    dictionary.Add(typeKey, typeKey);\r\n                }\r\n\r\n                return dictionary;\r\n            }\r\n        }\r\n```"},"comment":{"url":"https://api.github.com/repos/MvvmCross/MvvmCross-Plugins/issues/comments/248371150","html_url":"https://github.com/MvvmCross/MvvmCross-Plugins/issues/137#issuecomment-248371150","issue_url":"https://api.github.com/repos/MvvmCross/MvvmCross-Plugins/issues/137","id":248371150,"user":{"login":"LeRondPoint","id":15251145,"avatar_url":"https://avatars.githubusercontent.com/u/15251145?v=3","gravatar_id":"","url":"https://api.github.com/users/LeRondPoint","html_url":"https://github.com/LeRondPoint","followers_url":"https://api.github.com/users/LeRondPoint/followers","following_url":"https://api.github.com/users/LeRondPoint/following{/other_user}","gists_url":"https://api.github.com/users/LeRondPoint/gists{/gist_id}","starred_url":"https://api.github.com/users/LeRondPoint/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LeRondPoint/subscriptions","organizations_url":"https://api.github.com/users/LeRondPoint/orgs","repos_url":"https://api.github.com/users/LeRondPoint/repos","events_url":"https://api.github.com/users/LeRondPoint/events{/privacy}","received_events_url":"https://api.github.com/users/LeRondPoint/received_events","type":"User","site_admin":false},"created_at":"2016-09-20T17:25:15Z","updated_at":"2016-09-20T17:25:15Z","body":"Workaround :\r\n\r\n```\r\n        public TextProviderBuilder(string textFolder, string defaultTypeKey)\r\n            : base(Mvx.Resolve<ResourceLocator>().ResourcesNamespace, textFolder, new MvxEmbeddedJsonDictionaryTextProvider(false))\r\n        {\r\n            _DefaultTypeKey = defaultTypeKey;\r\n            LoadResources(string.Empty);\r\n        }\r\n\r\n        protected override IDictionary<string, string> ResourceFiles\r\n        {\r\n            get\r\n            {\r\n                Dictionary<string, string> dictionary = new Dictionary<string, string>();\r\n                IEnumerable<TypeInfo> localizedViewModelTypes = Mvx.Resolve<ResourceLocator>()\r\n                                                                   .ResourcesAssembly.DefinedTypes.Where(\r\n                                                                       t => t.IsSubclassOf(typeof(MvxLocalizedViewModel)));\r\n\r\n                if (!string.IsNullOrEmpty(_DefaultTypeKey))\r\n                {\r\n                    dictionary.Add(_DefaultTypeKey, _DefaultTypeKey);\r\n                }\r\n\r\n                foreach(TypeInfo type in localizedViewModelTypes)\r\n                {\r\n                    string typeKey = type.FullName;\r\n\r\n                    dictionary.Add(typeKey, typeKey);\r\n                }\r\n\r\n                return dictionary;\r\n            }\r\n        }\r\n```"}}
{"actor":{"display_login":"LeRondPoint"}}