pengweiqhca / Xunit.DependencyInjection

Use Microsoft.Extensions.DependencyInjection to resolve xUnit test cases.
MIT License
366 stars 49 forks source link

Add support for BuildHostApplicationBuilder #124

Open gilmar-sales opened 3 months ago

gilmar-sales commented 3 months ago

Support for BuildHost with the HostApplicationBuilder:

 public class Startup
{
        // with
        public void ConfigureHostApplicationBuilder(IHostApplicationBuilder hostApplicationBuilder)
        {
            // do something here...
        }

        // will be able to
        public IHost BuildHostApplicationBuilder(HostApplicationBuilder hostApplicationBuilder)
        {
            var hostApplication = hostApplicationBuilder.Build();
            // do something here...
            return hostApplication;
        }
}
WeihanLi commented 3 months ago

Could it be configured in the Configure method? We could inject any service registered in the service collection like IServiceProvider

https://github.com/pengweiqhca/Xunit.DependencyInjection/blob/d55ca649090492565a5f2ec088898370dd030724/test/Xunit.DependencyInjection.Test/HostApplicationBuilderTest.cs#L35

gilmar-sales commented 3 months ago

Configure method doesn't allow access to the IHost instance like the BuildHost method for the CreateHostBuilder, this could help if thirdparty libraries uses the IHost instead of the IServiceProvider

WeihanLi commented 3 months ago

what about supporting IHost in the Configure method?

pengweiqhca commented 3 months ago

Configure method doesn't allow access to the IHost instance like the BuildHost method for the CreateHostBuilder, this could help if thirdparty libraries uses the IHost instead of the IServiceProvider

That is not work?

public static void Configure(IHost host) => Counter++;

image