SpecFlowOSS / SpecFlow

#1 .NET BDD Framework. SpecFlow automates your testing & works with your existing code. Find Bugs before they happen. Behavior Driven Development helps developers, testers, and business representatives to get a better understanding of their collaboration
https://www.specflow.org/
Other
2.23k stars 752 forks source link

Autofac global container #2579

Closed rossmasday closed 2 years ago

rossmasday commented 2 years ago

…tional Attribute and two new method signatures.

Types of changes

Checklist:

SabotageAndi commented 2 years ago

@gasparnagy what do you say about this PR?

gasparnagy commented 2 years ago

Will check it tomorrow

rossmasday commented 2 years ago

I believe I have made the changes you require, I also did some refactoring and code improvements as well that should make it easier to extend for other scenarios and slightly easier to read, mainly that all finder methods are Func<ContainerBuilder, ContainerBuilder> this allows for a more fluent call signature and removes the issue where I had to return Object instead of void quirk of MethodInfo.Invoke(). It would have been cleaner to use Action<ContainerBuilder> instead but that obviously doesnt work with the legacy method and I did not want to have two FindMethods that were basically Identical. As per your suggestion the two new methods have the same signature, the old one is still available,

I noticed because the container in the original method is not registered with the internal Specflow container, it does not appear to have it's dispose method called, so I registered it and resolved it so that process is now invoked. I hope this will not introduce any issues, I would be surprised if it did, but I can remove it too if you prefer.

I added a couple of helper extension methods as well, if you're not keen on them I am happy to remove them.

I have also tagged the child scopes in line with the contexts, so if someone wanted to, they could scope registrations at any level instead of needing a new a new attribute in the future, as long as they registered these in the Global configuration. Like so: containerBuilder.RegisterType<MyType>().InstancePerMatchingLifetimeScope(nameof(FeatureContext))

Happy to discuss more if you need, thanks

rossmasday commented 2 years ago

Thanks for the review, I've updated the docs as requested. Wasn't sure about the version number for the change log so guessed what it would be

SabotageAndi commented 2 years ago

Thanks for your contribution to SpecFlow. Please submit your contributions to our SpecFlow Community Heroes program at https://specflow.org/community/submit-a-contribution/

SabotageAndi commented 2 years ago

Builds should be finished overnight and I will push new packages to NuGet.org tomorrow morning.