{"action":"opened","issue":{"url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/407","repository_url":"https://api.github.com/repos/simpleinjector/SimpleInjector","labels_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/407/labels{/name}","comments_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/407/comments","events_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/407/events","html_url":"https://github.com/simpleinjector/SimpleInjector/issues/407","id":222593898,"number":407,"title":"Hybrid lifestyle. What is wrong","user":{"login":"vitidev","id":2243958,"avatar_url":"https://avatars2.githubusercontent.com/u/2243958?v=3","gravatar_id":"","url":"https://api.github.com/users/vitidev","html_url":"https://github.com/vitidev","followers_url":"https://api.github.com/users/vitidev/followers","following_url":"https://api.github.com/users/vitidev/following{/other_user}","gists_url":"https://api.github.com/users/vitidev/gists{/gist_id}","starred_url":"https://api.github.com/users/vitidev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vitidev/subscriptions","organizations_url":"https://api.github.com/users/vitidev/orgs","repos_url":"https://api.github.com/users/vitidev/repos","events_url":"https://api.github.com/users/vitidev/events{/privacy}","received_events_url":"https://api.github.com/users/vitidev/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-04-19T01:53:19Z","updated_at":"2017-04-19T01:53:19Z","closed_at":null,"body":"I do not understand well why the combination of Lifestyle.Scoped and Lifestyle.Transient is caused \"lifestyle mismatch\". After all, unlike a singleton, scoped instanses are the same temporary as transient. \r\nAnd in general, the lifetime of an object depends on the retention references to instanse by someone. And therefore the aspect should not be on lifetime, but on the question \"should a new object be created at the given place or re-used existing\r\n\r\nAnd although my opinion does not coincide with the opinion of the author, I do not want to turn off the option\r\nContainer.Options.SuppressLifestyleMismatchVerification\r\n\r\nDowngrade LifeTime.Scoped -> LifeTime.Transient is meaningless, LifeTine.Transient ->LifeTime.Scoped causes errors.Thats why I use Lifestyle.CreateHybrid\r\n\r\n    class ScopedService\r\n    {\r\n        public ScopedService(IHybridDependency dep){}\r\n    }\r\n\r\n    public interface IHybridDependency{}\r\n    public class HybridDependency : IHybridDependency{}\r\n\r\n     static void Main(string[] args)\r\n      {\r\n            var container=new Container();\r\n            container.Options.DefaultScopedLifestyle=new AsyncScopedLifestyle();\r\n\r\n            container.Register<ScopedService>(Lifestyle.Scoped);\r\n\r\n            var hybridLifeStyle = Lifestyle.CreateHybrid(defaultLifestyle: Lifestyle.Scoped,\r\n                fallbackLifestyle: Lifestyle.Transient);\r\n            container.Register<IHybridDependency, HybridDependency>(hybridLifeStyle);\r\n\r\n            using (AsyncScopedLifestyle.BeginScope(container))\r\n            {\r\n                var service = container.GetInstance<ScopedService>();\r\n            }\r\n            Console.ReadKey();\r\n      }\r\n\r\ndefaultLifestyle:  The lifestyle to use when its GetCurrentScope method returns a scope.. \r\nfallbackLifestyle:  The lifestyle to use when the GetCurrentScope method of the defaultLifestyle argument returns null. \r\n\r\nBut I still get an error\r\n\r\n> SimpleInjector.ActivationException: 'A lifestyle mismatch is encountered. ScopedService (Async Scoped) depends on IHybridDependency implemented by HybridDependency (Hybrid Scoped / Transient). Lifestyle mismatches can cause concurrency bugs in your application. Please see https://simpleinjector.org/dialm to understand this problem and how to solve it.'\r\n\r\n\r\n\r\nWhy the error?"}}
{"actor":{"display_login":"vitidev"}}