Closed rangers-globecar closed 2 years ago
Interesting question @robert-stratecglobal -- although it's not related to the Microsoft.DependencyInjection
framework specifically, I can understand you want this xUnit feature to work.
I've created a test which should cover this issue and committed it in the https://github.com/solidtoken/SpecFlow.DependencyInjection/tree/feature/75-ITestOutputHelper branch. Let me know if this truly the issue you're talking about.
The challenge imho is to solve this without SpecFlow.DependencyInjection
needing a dependency on xUnit specifically. I'll need some time to further investigate and think of a correct way to solve this.
The ISpecflowOutputHelper could be an alternative that would work as well.
Isn't there a way to "pickup" what is in the BoDi ? That way, any future enhancement to the DI and any third party plugin would automatically insert as well...
public class TestService : ITestService {
public TestService(ISpecflowOutputHelper output) //or ITestOutputHelper
{
//This is what I would like
}
}
Isn't there a way to "pickup" what is in the BoDi ? That way, any future enhancement to the DI and any third party plugin would automatically insert as well...
That would make sense @bobbyangers but the current implementation completely replaces BoDi. So either it needs to fall back to BoDi if a dependency cannot be found in Microsoft's IServiceCollection
(seems hard and might break existing implementations), or we add the dependencies available in BoDi to the IServiceCollection
explicitly (requires bit of extra setup but should not break existing implementations).
I'll investigate the latter.
@mbhoek
Check out Corvus.Testing
they have an elegant way of handling the problem.... by using "hooks".... it's possible to "inject" more stuff and even do 'automatically' do some stuff in the background....
https://github.com/AdCodicem/SpecFlowMicrosoftDependencyInjection
solved it with the AddDelegated
(so no dependency on xUnit from the lib)
public void ConfigureServices(IServiceCollection services)
{
services
// ITestOutputHelper is automatically registered by Specflow when using xUnit runner
.AddDelegated<ITestOutputHelper>() ///!< ------------------
// Calculator can use ITestOutputHelper as it's registered above to delegate the resolution to the original container
.AddTransient<ICalculator, Calculator>();
}
Good logging is essential, so I also need the ITestOutputHelper
@304NotModified Do you mind if I copy/paste your AddDelegated
solution into this project?
It isn't mine ;)
Right, sorry. @AdCodicem was involved early on but created their own plugin instead, apologies for the mix-up. I'll see what I can do!
@mbhoek You can do copy anything you need from my repo, I think it's better to have only one project to maintain, and as I started a company of my own, I have less time to spend on my project.
If it's ok for you I'll add a message to redirect the users to your project :slightly_smiling_face:
@AdCodicem Congratulations on starting your own company! I'm happy to keep maintaining this project, I think we've had a couple of great contributions over time. I do however struggle with available time too. I'll take some time this weekend to look at your code and @shlomiassaf 's PR #74 and see how we can make this the best MDI plugin available.
Of course I will keep on crediting all contributors. Thanks again!
Guess this plugin is not the only one struggling with this issue: https://github.com/SpecFlowOSS/SpecFlow/issues/2550
Also want to track this one: https://github.com/SpecFlowOSS/SpecFlow/issues/2353
Thank you! Don't hesitate to ask me if you need any help 🙂
@AdCodicem I'm trying to figure out whether I want to copy your IServiceConfigurator
pattern or just stick to the static
implementation currently in this plugin. Can you explain a bit about your thinking behind it?
@mbhoek the IServiceConfigurator
purpose is to enable services registration in several configuration classes, at the time I needed to separate some configuration for readability.
You can see in this part of the code where the plugin search for IServiceConfigurator
implementations :
Edit:
Also, I wanted to manage the creation of the Service collection and the interface allowed me to restrict the way the developer implemented the ConfigurationServices
method and so, less issues ensued
@robert-stratecglobal @bobbyangers ISpecFlowOutputHelper
(and other SpecFlow infrastructure) is available in release v3.9.3.
Hi, We are using SpecFlow.xUnit; is there anyway to add/capture the ITestOutputHelper, in the same way [Binding] are being automatically ?