{"action":"closed","issue":{"url":"https://api.github.com/repos/autofac/Autofac/issues/272","repository_url":"https://api.github.com/repos/autofac/Autofac","labels_url":"https://api.github.com/repos/autofac/Autofac/issues/272/labels{/name}","comments_url":"https://api.github.com/repos/autofac/Autofac/issues/272/comments","events_url":"https://api.github.com/repos/autofac/Autofac/issues/272/events","html_url":"https://github.com/autofac/Autofac/issues/272","id":26091376,"number":272,"title":"PreserveExistingDefaults doesn't work in nested lifetime scopes","user":{"login":"alexmg","id":131293,"avatar_url":"https://avatars.githubusercontent.com/u/131293?v=3","gravatar_id":"","url":"https://api.github.com/users/alexmg","html_url":"https://github.com/alexmg","followers_url":"https://api.github.com/users/alexmg/followers","following_url":"https://api.github.com/users/alexmg/following{/other_user}","gists_url":"https://api.github.com/users/alexmg/gists{/gist_id}","starred_url":"https://api.github.com/users/alexmg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexmg/subscriptions","organizations_url":"https://api.github.com/users/alexmg/orgs","repos_url":"https://api.github.com/users/alexmg/repos","events_url":"https://api.github.com/users/alexmg/events{/privacy}","received_events_url":"https://api.github.com/users/alexmg/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/autofac/Autofac/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/autofac/Autofac/labels/module-core","name":"module-core","color":"d4c5f9"},{"url":"https://api.github.com/repos/autofac/Autofac/labels/priority-medium","name":"priority-medium","color":"FFFFFF"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2014-01-22T14:02:25Z","updated_at":"2016-06-30T02:57:27Z","closed_at":"2016-06-30T02:57:27Z","body":"_From [mrdont@mail.ru](https://code.google.com/u/mrdont@mail.ru/) on November 19, 2010 12:06:33_\n\nWhat steps will reproduce the problem? 1. Register one implementation of a service in root container.\r\n2. Begin new lifetime scope and register another implementation of the service, but preserving existing defaults.\r\n3. Resolve service in the created scope.\r\n\r\nWhat is the expected output? First implementation of the service.\r\nWhat do you see instead? Another implementation of the service.\r\n\r\nService registered in root container is also default implementation in nested scope, until another implementation is registered. But when I specify PreserveExistingDefaults, I expect that new registration won't override existing registrations of the same service.\r\n\r\nThe following code would reproduce the problem:\r\n\r\n        public interface IService {}\r\n        public class Service1: IService {}\r\n        public class Service2: IService {} \r\n\r\n        [Test]\r\n        public void PreserveExternalOverrides()\r\n        {\r\n            var builder = new ContainerBuilder();\r\n            builder.RegisterType<Service1>().As<IService>();\r\n            var context = builder.Build();\r\n\r\n            var newContext = context.BeginLifetimeScope(b => b.RegisterType<Service2>().As<IService>().PreserveExistingDefaults());\r\n\r\n            Assert.IsInstanceOf<Service1>(context.Resolve<IService>());\r\n            Assert.IsInstanceOf<Service1>(newContext.Resolve<IService>()); // fails\r\n\r\n        }\n\n_Original issue: http://code.google.com/p/autofac/issues/detail?id=272_"}}
{"actor":{"display_login":"alexmg"}}