{"action":"created","issue":{"url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/34","labels_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/34/labels{/name}","comments_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/34/comments","events_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/34/events","html_url":"https://github.com/simpleinjector/SimpleInjector/issues/34","id":71096419,"number":34,"title":"Registration of a service after resolution","user":{"login":"prasannavl","id":559409,"avatar_url":"https://avatars.githubusercontent.com/u/559409?v=3","gravatar_id":"","url":"https://api.github.com/users/prasannavl","html_url":"https://github.com/prasannavl","followers_url":"https://api.github.com/users/prasannavl/followers","following_url":"https://api.github.com/users/prasannavl/following{/other_user}","gists_url":"https://api.github.com/users/prasannavl/gists{/gist_id}","starred_url":"https://api.github.com/users/prasannavl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prasannavl/subscriptions","organizations_url":"https://api.github.com/users/prasannavl/orgs","repos_url":"https://api.github.com/users/prasannavl/repos","events_url":"https://api.github.com/users/prasannavl/events{/privacy}","received_events_url":"https://api.github.com/users/prasannavl/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-04-26T17:30:49Z","updated_at":"2015-04-27T20:47:33Z","closed_at":"2015-04-27T20:47:33Z","body":"Hi, \r\n\r\nI understand that SimpleInjector's container is locked, and doesn't let you register services after the first resolution, by design. But there are many cases where one would like to resolve certain services during the startup-phase, in between registrations. I've also seen tid-bits of these discussions in many places, but unfortunately, I was unable to get a clean solution for the same so far. The documentation also seems to touch on this a bit, but just barely.\r\n\r\nI was wondering if you could please give a quick scrip on what's the intended best way to accomplish this:\r\n\r\n```c# \r\n\r\npublic BootstrapperClass1 {\r\n  public void Register(Container c)\r\n  {\r\n      c.Register<IService1, Service1>();\r\n  }\r\n}\r\n\r\npublic BootstrapperClass2 {\r\n  public void Register(Container c)\r\n  {\r\n     // This is just to substantiate the notion \r\n     // that the service has to be resolved here, and more registration\r\n     // to proceed after that. \r\n     if (c.GetInstance<IService1>().Version == 1)\r\n     {\r\n           c.Register<IService2, Service2v1>();\r\n      }\r\n      else {\r\n        c.Register<IService2, Service2v2>();\r\n      }\r\n  }\r\n}\r\n\r\n```\r\n\r\nOne obvious way that I see is to use the UnresolvedType event. But the obvious problem is that, this ends up complicating the whole registration logic for anything beyond that. And you have to end up doing almost the entire rest of the registration logic as a part of that event, which seems highly unnatural. \r\n\r\nA whole bunch of my projects use multi-stage bootstrappers like these, where a later bootstrapper will need to examine registered services so far before they make their registrations and this seems make it quite difficult to migrate to SI. \r\n\r\nThe only way I seem to be able to workaround this is by creating a whole bunch of different containers, and composing the registrations of the containers to a new one. This is bugging me since it isn't the cleanest approach, and also becomes very expensive on the startup path, as the startup stages increase."},"comment":{"url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/comments/96815075","html_url":"https://github.com/simpleinjector/SimpleInjector/issues/34#issuecomment-96815075","issue_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/34","id":96815075,"user":{"login":"prasannavl","id":559409,"avatar_url":"https://avatars.githubusercontent.com/u/559409?v=3","gravatar_id":"","url":"https://api.github.com/users/prasannavl","html_url":"https://github.com/prasannavl","followers_url":"https://api.github.com/users/prasannavl/followers","following_url":"https://api.github.com/users/prasannavl/following{/other_user}","gists_url":"https://api.github.com/users/prasannavl/gists{/gist_id}","starred_url":"https://api.github.com/users/prasannavl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prasannavl/subscriptions","organizations_url":"https://api.github.com/users/prasannavl/orgs","repos_url":"https://api.github.com/users/prasannavl/repos","events_url":"https://api.github.com/users/prasannavl/events{/privacy}","received_events_url":"https://api.github.com/users/prasannavl/received_events","type":"User","site_admin":false},"created_at":"2015-04-27T20:47:33Z","updated_at":"2015-04-27T20:47:33Z","body":"Fair enough. Thanks for your time and help with this. I see if I can make it work by shuffling the design a bit, or go probably go back to Autofac as a last resort."}}