Xunit.DependencyInjection icon indicating copy to clipboard operation
Xunit.DependencyInjection copied to clipboard

Add support for BuildHostApplicationBuilder

Open gilmar-sales opened this issue 1 year ago • 4 comments

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;
        }
}

gilmar-sales avatar Jun 12 '24 16:06 gilmar-sales

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

WeihanLi avatar Jun 12 '24 17:06 WeihanLi

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

gilmar-sales avatar Jun 12 '24 19:06 gilmar-sales

what about supporting IHost in the Configure method?

WeihanLi avatar Jun 13 '24 00:06 WeihanLi

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

pengweiqhca avatar Jun 16 '24 09:06 pengweiqhca