{"action":"created","issue":{"url":"https://api.github.com/repos/myie/SpecFlow.CastleWindsor/issues/2","repository_url":"https://api.github.com/repos/myie/SpecFlow.CastleWindsor","labels_url":"https://api.github.com/repos/myie/SpecFlow.CastleWindsor/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/myie/SpecFlow.CastleWindsor/issues/2/comments","events_url":"https://api.github.com/repos/myie/SpecFlow.CastleWindsor/issues/2/events","html_url":"https://github.com/myie/SpecFlow.CastleWindsor/issues/2","id":320267984,"number":2,"title":"Specflow Hooks IObjectContainer null","user":{"login":"danny-bos-developer","id":23095670,"avatar_url":"https://avatars3.githubusercontent.com/u/23095670?v=4","gravatar_id":"","url":"https://api.github.com/users/danny-bos-developer","html_url":"https://github.com/danny-bos-developer","followers_url":"https://api.github.com/users/danny-bos-developer/followers","following_url":"https://api.github.com/users/danny-bos-developer/following{/other_user}","gists_url":"https://api.github.com/users/danny-bos-developer/gists{/gist_id}","starred_url":"https://api.github.com/users/danny-bos-developer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danny-bos-developer/subscriptions","organizations_url":"https://api.github.com/users/danny-bos-developer/orgs","repos_url":"https://api.github.com/users/danny-bos-developer/repos","events_url":"https://api.github.com/users/danny-bos-developer/events{/privacy}","received_events_url":"https://api.github.com/users/danny-bos-developer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-05-04T13:06:50Z","updated_at":"2018-05-08T09:58:55Z","closed_at":null,"author_association":"NONE","body":"Hi, I'm using this specflow plugin because we have castle in all out projects. I only have one problem, specflow has some hooks where you can execute code:\r\n[BeforeFeature()]\r\npublic static void BeforeFeature(IObjectContainer objectContainer)        {        }\r\n\r\n[AfterFeature()]\r\npublic static void AfterFeature(IObjectContainer objectContainer)        {        }\r\n\r\n[AfterScenario()]\r\npublic static void AfterScenario(IObjectContainer objectContainer)        {        }\r\n\r\n[BeforeScenario()]\r\npublic static void BeforeScenario(IObjectContainer objectContainer)        {        }\r\n\r\nAll hooks get null injected.\r\n\r\nI tried to this code:\r\nargs.ObjectContainer.RegisterFactoryAs(() =>\r\n                {\r\n                    var containerBuilderFinder = args.ObjectContainer.Resolve<IContainerFinder>();\r\n                    var containerBuilder = containerBuilderFinder.GetCreateScenarioContainer();\r\n                    var container = containerBuilder.Invoke();\r\n                    return container;\r\n                });\r\ninto the RegisterGlobalDependencies event and alongside with CustomizeGlobalDependencies but nothing seems to work.\r\n\r\nThen I tried to change the signature of the method to this:\r\npublic static void BeforeScenario(ITestdependency testDependency). In this case I sometimes get an instance and sometimes still null.\r\n\r\nAny help would be usefull, if you want my sourcecode to reproduce things, let me know.\r\n\r\nKind regards,\r\nDanny\r\n"},"comment":{"url":"https://api.github.com/repos/myie/SpecFlow.CastleWindsor/issues/comments/387350685","html_url":"https://github.com/myie/SpecFlow.CastleWindsor/issues/2#issuecomment-387350685","issue_url":"https://api.github.com/repos/myie/SpecFlow.CastleWindsor/issues/2","id":387350685,"user":{"login":"danny-bos-developer","id":23095670,"avatar_url":"https://avatars3.githubusercontent.com/u/23095670?v=4","gravatar_id":"","url":"https://api.github.com/users/danny-bos-developer","html_url":"https://github.com/danny-bos-developer","followers_url":"https://api.github.com/users/danny-bos-developer/followers","following_url":"https://api.github.com/users/danny-bos-developer/following{/other_user}","gists_url":"https://api.github.com/users/danny-bos-developer/gists{/gist_id}","starred_url":"https://api.github.com/users/danny-bos-developer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danny-bos-developer/subscriptions","organizations_url":"https://api.github.com/users/danny-bos-developer/orgs","repos_url":"https://api.github.com/users/danny-bos-developer/repos","events_url":"https://api.github.com/users/danny-bos-developer/events{/privacy}","received_events_url":"https://api.github.com/users/danny-bos-developer/received_events","type":"User","site_admin":false},"created_at":"2018-05-08T09:58:55Z","updated_at":"2018-05-08T09:58:55Z","author_association":"NONE","body":"Hi Hyie,\r\n\r\nI solved the problem by adjusting the Initialize method in the plugin itself like this:\r\n\r\npublic void Initialize(RuntimePluginEvents runtimePluginEvents, RuntimePluginParameters runtimePluginParameters)\r\n        {\r\n\r\n            // Wire up our Windsor resolver & container locater to the\r\n            // global IOC container\r\n            runtimePluginEvents.CustomizeGlobalDependencies += (sender, args) =>\r\n            {\r\n                // temporary fix for CustomizeGlobalDependencies called multiple times\r\n                // see https://github.com/techtalk/SpecFlow/issues/948\r\n                if (args.ObjectContainer.IsRegistered<IContainerFinder>()) return;\r\n                args.ObjectContainer.RegisterTypeAs<WindsorResolver, ITestObjectResolver>();\r\n                args.ObjectContainer.RegisterTypeAs<ContainerFinder, IContainerFinder>();\r\n                args.ObjectContainer.RegisterFactoryAs(() =>\r\n                {\r\n                    var containerBuilderFinder = args.ObjectContainer.Resolve<IContainerFinder>();\r\n                    var containerBuilder = containerBuilderFinder.GetCreateScenarioContainer();\r\n                    var container = containerBuilder.Invoke();\r\n                    return container;\r\n                });\r\n            };\r\n\r\n            // Replace the IOC container with our windsor container\r\n            // which is defined in a method marked with the [ScenarioDependecies] Attribute\r\n            //runtimePluginEvents.CustomizeScenarioDependencies += (sender, args) =>\r\n            //{\r\n            //    args.ObjectContainer.RegisterFactoryAs(() =>\r\n            //    {\r\n            //        var containerBuilderFinder = args.ObjectContainer.Resolve<IContainerFinder>();\r\n            //        var containerBuilder = containerBuilderFinder.GetCreateScenarioContainer();\r\n            //        var container = containerBuilder.Invoke();\r\n            //        return container;\r\n            //    });\r\n            //};\r\n        }\r\n\r\nNow the hooks in the steps files are working, you can supply a list of arguments the needs to be injected like this:\r\n\r\n[BeforeScenario()]\r\n        public static void BeforeScenario(ITestDependency testDependency, ITestDependencyB testDependencyb)\r\n        {\r\n            // bleh static...\r\n        }\r\n\r\n        [BeforeScenario()]\r\n        public void BeforeScenarioX(ITestDependency testDependency, , ITestDependencyB testDependencyb)\r\n        {\r\n            // yay non static is working too :D\r\n        }\r\n\r\nOnly things that don't work are the BeforeFeature and AfterFeature. Then all argument are null. This is not a problem to me, it has to do with the available RuntimePluginEvents; there you only get hooks for global and scenario events, not for feature events. Specflow has some requests to make to available, so maybe in the future we're able to hook up things for the other two hooks.\r\n\r\nHope I gave you enough explanation and you might wanna adjust you're own plugin so the issue can be resolved.\r\n\r\nKind regards\r\nDanny"}}
{"actor":{"display_login":"danny-bos-developer"}}