{"action":"created","issue":{"url":"https://api.github.com/repos/PrismLibrary/Prism/issues/877","repository_url":"https://api.github.com/repos/PrismLibrary/Prism","labels_url":"https://api.github.com/repos/PrismLibrary/Prism/issues/877/labels{/name}","comments_url":"https://api.github.com/repos/PrismLibrary/Prism/issues/877/comments","events_url":"https://api.github.com/repos/PrismLibrary/Prism/issues/877/events","html_url":"https://github.com/PrismLibrary/Prism/issues/877","id":196311988,"number":877,"title":"Order of operations issue with Dependency registrations","user":{"login":"scionwest","id":1865693,"avatar_url":"https://avatars.githubusercontent.com/u/1865693?v=3","gravatar_id":"","url":"https://api.github.com/users/scionwest","html_url":"https://github.com/scionwest","followers_url":"https://api.github.com/users/scionwest/followers","following_url":"https://api.github.com/users/scionwest/following{/other_user}","gists_url":"https://api.github.com/users/scionwest/gists{/gist_id}","starred_url":"https://api.github.com/users/scionwest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scionwest/subscriptions","organizations_url":"https://api.github.com/users/scionwest/orgs","repos_url":"https://api.github.com/users/scionwest/repos","events_url":"https://api.github.com/users/scionwest/events{/privacy}","received_events_url":"https://api.github.com/users/scionwest/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-12-19T01:00:52Z","updated_at":"2016-12-19T20:59:17Z","closed_at":null,"body":"- Platform: Xamarin Forms\r\n- Prism version: Prism.Forms\r\n\r\n### Repro steps\r\n\r\nUsing the Prism.Autofac.Forms library, I'd like to see adjustments to how the base class handles registration types. For example, I have a Xamarin.Forms project with an Android and iOS app with a PCL library. The App.cs file in my PCL inherits from `PrismApplication` and is provided with a custom interface called `IDependencyRegistration`.\r\n\r\n```C#\r\n    public interface IDependencyRegistration\r\n    {\r\n        void RegisterDependencies();\r\n    }\r\n\r\n    public class App : PrismApplication\r\n    {\r\n        private IDependencyRegistration dependencyRegistration;\r\n\r\n        public App(IDependencyRegistration dependencyRegistration)\r\n        {\r\n            this.dependencyRegistration = dependencyRegistration;\r\n        }\r\n\r\n        protected override void OnInitialized()\r\n        {\r\n            MobileCenter.Start(typeof(Analytics), typeof(Crashes));\r\n            this.NavigationService.NavigateAsync(\"MainPage\");\r\n        }\r\n\r\n        protected override void RegisterTypes()\r\n        {\r\n            this.dependencyRegistration?.RegisterDependencies();\r\n        }\r\n    }\r\n```\r\n\r\nThis allows each platform to register dependency implementations that are platform specific.\r\n\r\n```c#\r\n    internal class AndroidDependencyService : IDependencyRegistration\r\n    {\r\n        public void RegisterDependencies()\r\n        {\r\n            DependencyService.Register<AndroidSqliteProvider>();\r\n        }\r\n    }\r\n\r\n    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity\r\n    {\r\n        protected override void OnCreate(Bundle bundle)\r\n        {\r\n            // ......\r\n            var app = new App(new AndroidDependencyService());\r\n            LoadApplication(app);\r\n        }\r\n    }\r\n```\r\n\r\nWith the current implementation of the `PrismApplication`, my constructor is not allowed to run, before the `RegisterTypes` method is called. This prevents me from running Type registration stuff in that method. I know I could easily just call `dependencyRegistration.RegisterDependencies()` from within my constructor, but then my code has platform registration and shared registration happening in two different places.\r\n\r\nLooking at [PrismApplicationBase](https://github.com/PrismLibrary/Prism/blob/master/Source/Xamarin/Prism.Forms/PrismApplicationBase.cs#L46) it looks like you initialize the app in your constructor, which eventually leads to invoking `RegisterTypes`. I'd propose moving the initialization out of the constructor (giving sub-classes a chance to configure themselves) and into the `OnStart` method of the base Xamarin `Application` class.\r\n\r\n```C#\r\n        protected override void OnStart() \r\n        { \r\n                InitializeInternal();\r\n        } \r\n```\r\n\r\nThis allows sub-classed Apps to take dependencies from each platform, configure them if needed, and then use them during the actual Prism initialization process."},"comment":{"url":"https://api.github.com/repos/PrismLibrary/Prism/issues/comments/268076674","html_url":"https://github.com/PrismLibrary/Prism/issues/877#issuecomment-268076674","issue_url":"https://api.github.com/repos/PrismLibrary/Prism/issues/877","id":268076674,"user":{"login":"bartlannoeye","id":5115577,"avatar_url":"https://avatars.githubusercontent.com/u/5115577?v=3","gravatar_id":"","url":"https://api.github.com/users/bartlannoeye","html_url":"https://github.com/bartlannoeye","followers_url":"https://api.github.com/users/bartlannoeye/followers","following_url":"https://api.github.com/users/bartlannoeye/following{/other_user}","gists_url":"https://api.github.com/users/bartlannoeye/gists{/gist_id}","starred_url":"https://api.github.com/users/bartlannoeye/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bartlannoeye/subscriptions","organizations_url":"https://api.github.com/users/bartlannoeye/orgs","repos_url":"https://api.github.com/users/bartlannoeye/repos","events_url":"https://api.github.com/users/bartlannoeye/events{/privacy}","received_events_url":"https://api.github.com/users/bartlannoeye/received_events","type":"User","site_admin":false},"created_at":"2016-12-19T20:59:17Z","updated_at":"2016-12-19T20:59:17Z","body":"The code linked in #742 is not in the latest pre-release package yet. I hope to find some time one of the upcoming days to push a new prelease package. If you could post the code to help us reproduce the issue, I'll test that against the lat codebase as well."}}
{"actor":{"display_login":"bartlannoeye"}}